Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from picamera2 import Picamera2, Preview
- from picamera2.controls import Controls
- # Initialize camera
- picam2 = Picamera2()
- # Configure for the best quality sensor format
- preview_config = picam2.create_preview_configuration()
- capture_config = picam2.create_still_configuration(raw={'size': (4608, 2592), 'format': 'SRGGB10_CSI2P'}, main={'size': (4608, 2592), 'format': 'BGR888'})
- # Configure preview mode
- picam2.configure(preview_config)
- # Start the camera
- picam2.start_preview(Preview.QTGL)
- picam2.start()
- time.sleep(1) # Let the camera warm up
- # Set manual controls using the "direct" attribute method
- with picam2.controls as ctrl:
- ctrl.AnalogueGain = 1.1228070259094238 # Lowest possible value
- ctrl.ExposureTime = 10000 # Shutter speed in microseconds, e.g., 1/100s
- ctrl.AeEnable = False # Disable auto exposure
- ctrl.AwbMode = 6 # Set to daylight white balance
- ctrl.Sharpness = 0.0 # Set sharpness level to 0
- ctrl.NoiseReductionMode = 0 # Turn off noise reduction
- ctrl.Saturation = 0.0 # Set saturation to the lowest possible value
- ctrl.Contrast = 0.0 # Set contrast level to 0
- time.sleep(2) # Give time for the settings to take effect
- # Capture a single image
- jpeg_filename = "image.jpg"
- dng_filename = "image.dng"
- # Capture JPEG first
- picam2.switch_mode_and_capture_file(capture_config, jpeg_filename, name="main")
- print(f"Captured {jpeg_filename}")
- # Reapply settings before capturing DNG
- with picam2.controls as ctrl:
- ctrl.AnalogueGain = 1.1228070259094238
- ctrl.ExposureTime = 10000
- ctrl.AeEnable = False
- ctrl.AwbMode = 6
- ctrl.Sharpness = 0.0
- ctrl.NoiseReductionMode = 0
- ctrl.Saturation = 0.0
- ctrl.Contrast = 0.0
- time.sleep(2) # Give time for the settings to take effect
- # Capture DNG
- picam2.switch_mode_and_capture_file(capture_config, dng_filename, name="raw")
- print(f"Captured {dng_filename}")
- picam2.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement