picamera2
picamera2 copied to clipboard
[INFO] stack_processed.py
Thanks for providing so many useful examples, like the stack_processed.py!
#!/usr/bin/python3
import cv2
import numpy as np
from picamera2 import Picamera2
exposure_time = 60000 # put your own numbers here
num_frames = 6
# We must tweak the tuning to disable the non-linear gamma transform. Load the
# tuning file for the sensor that you have attached.
tuning = Picamera2.load_tuning_file("imx477.json")
contrast_algo = Picamera2.find_tuning_algo(tuning, "rpi.contrast")
gamma_curve = contrast_algo["gamma_curve"]
contrast_algo["ce_enable"] = 0
contrast_algo["gamma_curve"] = [0, 0, 65535, 65535]
# Create a gamma lookup table to apply at the end.
gamma_x = np.array(gamma_curve[::2], dtype=float) * 255 / 65535
gamma_y = np.array(gamma_curve[1::2], dtype=float) * 255 / 65535
gamma_lut = np.interp(range(num_frames * 255 + 1), gamma_x, gamma_y, right=255).astype(np.uint8)
picam2 = Picamera2(tuning=tuning)
config = picam2.create_still_configuration({"format": "RGB888"}, buffer_count=2)
picam2.configure(config)
images = []
picam2.set_controls({"ExposureTime": exposure_time // num_frames, "AnalogueGain": 1.0})
picam2.start()
for i in range(num_frames):
images.append(picam2.capture_array())
# Add the images up, apply the gamma transform and we're done.
accumulated = images.pop(0).astype(np.uint16)
for image in images:
accumulated += image
accumulated = gamma_lut[accumulated]
cv2.imwrite("accumulated.jpg", accumulated)
i) How can it be that multiple exposures are merged, if one sets only one exposure time? And if there are different exposure frames, how constant is this program in terms of exposure times? For example, if you set 10 frames, how random/arbitrary are these 10 frames in terms of capture timing?
ii) How far can you max out the frames? What would be a reasonable value and why?
iii) Adding up the frames creates a high dynamic range image (hdr), where does the compression of the dynamic range take place (tone mapping)?
iv) How to shorten the code so that no gamma transformation is added?
Best regards Paul