Advertisement
Iequezada

picamctrl

May 18th, 2024 (edited)
725
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. import time
  2. from picamera2 import Picamera2, Preview
  3. from picamera2.controls import Controls
  4.  
  5. # Initialize camera
  6. picam2 = Picamera2()
  7.  
  8. # Configure for the best quality sensor format
  9. preview_config = picam2.create_preview_configuration()
  10. capture_config = picam2.create_still_configuration(raw={'size': (4608, 2592), 'format': 'SRGGB10_CSI2P'}, main={'size': (4608, 2592), 'format': 'BGR888'})
  11.  
  12. # Configure preview mode
  13. picam2.configure(preview_config)
  14.  
  15. # Start the camera
  16. picam2.start_preview(Preview.QTGL)
  17. picam2.start()
  18. time.sleep(1)  # Let the camera warm up
  19.  
  20. # Set manual controls using the "direct" attribute method
  21. with picam2.controls as ctrl:
  22.     ctrl.AnalogueGain = 1.1228070259094238  # Lowest possible value
  23.     ctrl.ExposureTime = 10000               # Shutter speed in microseconds, e.g., 1/100s
  24.     ctrl.AeEnable = False                   # Disable auto exposure
  25.     ctrl.AwbMode = 6                        # Set to daylight white balance
  26.     ctrl.Sharpness = 0.0                    # Set sharpness level to 0
  27.     ctrl.NoiseReductionMode = 0             # Turn off noise reduction
  28.     ctrl.Saturation = 0.0                   # Set saturation to the lowest possible value
  29.     ctrl.Contrast = 0.0                     # Set contrast level to 0
  30.  
  31. time.sleep(2)  # Give time for the settings to take effect
  32.  
  33. # Capture a single image
  34. jpeg_filename = "image.jpg"
  35. dng_filename = "image.dng"
  36.  
  37. # Capture JPEG first
  38. picam2.switch_mode_and_capture_file(capture_config, jpeg_filename, name="main")
  39. print(f"Captured {jpeg_filename}")
  40.  
  41. # Reapply settings before capturing DNG
  42. with picam2.controls as ctrl:
  43.     ctrl.AnalogueGain = 1.1228070259094238
  44.     ctrl.ExposureTime = 10000
  45.     ctrl.AeEnable = False
  46.     ctrl.AwbMode = 6
  47.     ctrl.Sharpness = 0.0
  48.     ctrl.NoiseReductionMode = 0
  49.     ctrl.Saturation = 0.0
  50.     ctrl.Contrast = 0.0
  51.  
  52. time.sleep(2)  # Give time for the settings to take effect
  53.  
  54. # Capture DNG
  55. picam2.switch_mode_and_capture_file(capture_config, dng_filename, name="raw")
  56. print(f"Captured {dng_filename}")
  57.  
  58. picam2.stop()
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement