2023-03-23 12:36:45 +01:00
|
|
|
#!//usr/bin/python3
|
|
|
|
|
2023-03-23 14:32:50 +01:00
|
|
|
import numpyHDR
|
2023-03-24 15:37:52 +01:00
|
|
|
from PIL import Image
|
2023-03-23 12:36:45 +01:00
|
|
|
from picamera2 import Picamera2
|
2023-03-23 14:47:04 +01:00
|
|
|
from libcamera import controls
|
2023-03-24 17:00:09 +01:00
|
|
|
import time
|
2023-03-23 12:36:45 +01:00
|
|
|
|
|
|
|
picam2 = Picamera2()
|
|
|
|
config = picam2.create_still_configuration()
|
|
|
|
picam2.configure(config)
|
2023-03-24 15:37:52 +01:00
|
|
|
picam2.set_controls({"AwbEnable": 1})
|
|
|
|
picam2.set_controls({"AeEnable": 1})
|
2023-03-24 16:51:40 +01:00
|
|
|
picam2.set_controls({"AfMode": controls.AfModeEnum.Manual })
|
|
|
|
picam2.set_controls({"LensPosition": 0.0 })
|
2023-03-24 15:37:52 +01:00
|
|
|
#picam2.set_controls({"AnalogueGain": 1.0})
|
2023-03-23 12:36:45 +01:00
|
|
|
picam2.start()
|
2023-03-23 14:49:23 +01:00
|
|
|
time.sleep(1)
|
2023-03-24 15:37:52 +01:00
|
|
|
|
|
|
|
print(picam2.capture_metadata())
|
|
|
|
start = picam2.capture_metadata()
|
|
|
|
exposure_start = start["ExposureTime"]
|
|
|
|
gain_start = start["AnalogueGain"]
|
|
|
|
|
|
|
|
picam2.set_controls({"AeEnable": 0})
|
|
|
|
confirmed = picam2.capture_metadata()["AeLocked"]
|
|
|
|
while confirmed != True:
|
|
|
|
confimed = picam2.capture_metadata()["AeLocked"]
|
|
|
|
time.sleep(.1)
|
|
|
|
|
|
|
|
picam2.set_controls({"AnalogueGain": gain_start})
|
|
|
|
confirmed = picam2.capture_metadata()["AnalogueGain"]
|
|
|
|
while confirmed != gain_start in range(gain_start -0.1, gain_start +0.1):
|
|
|
|
confimed = picam2.capture_metadata()["AnalogueGain"]
|
|
|
|
time.sleep(.1)
|
|
|
|
|
2023-03-24 16:51:40 +01:00
|
|
|
ev1 = picam2.capture_array()
|
|
|
|
#print("Picture one is done")
|
|
|
|
|
|
|
|
ev_low = int(exposure_start / 2)
|
2023-03-24 15:37:52 +01:00
|
|
|
picam2.set_controls({"ExposureTime": ev_low})
|
|
|
|
confirmed = picam2.capture_metadata()["ExposureTime"]
|
|
|
|
while confirmed not in range(ev_low -100, ev_low + 100 ):
|
|
|
|
confirmed = picam2.capture_metadata()["ExposureTime"]
|
|
|
|
time.sleep(.01)
|
|
|
|
|
2023-03-24 16:51:40 +01:00
|
|
|
#print("2",confirmed)
|
2023-03-24 15:37:52 +01:00
|
|
|
ev2 = picam2.capture_array()
|
2023-03-24 16:51:40 +01:00
|
|
|
#print("Picture 2 is captured to array")
|
2023-03-24 15:37:52 +01:00
|
|
|
|
2023-03-24 16:51:40 +01:00
|
|
|
ev_high = int(exposure_start * 2)
|
2023-03-24 15:37:52 +01:00
|
|
|
picam2.set_controls({"ExposureTime": ev_high})
|
|
|
|
confirmed = picam2.capture_metadata()["ExposureTime"]
|
|
|
|
while confirmed not in range(ev_high -100, ev_high + 100 ):
|
|
|
|
confirmed = picam2.capture_metadata()["ExposureTime"]
|
|
|
|
time.sleep(.01)
|
|
|
|
|
2023-03-24 16:51:40 +01:00
|
|
|
#print("3",confirmed)
|
2023-03-24 15:37:52 +01:00
|
|
|
ev3 = picam2.capture_array()
|
2023-03-24 16:51:40 +01:00
|
|
|
#print("Picture 3 is captured")
|
2023-03-24 15:37:52 +01:00
|
|
|
print("Saving..")
|
|
|
|
|
|
|
|
image = Image.fromarray(ev1)
|
|
|
|
image.save(f"test_hdr0.jpg", quality=50)
|
|
|
|
|
|
|
|
image = Image.fromarray(ev2)
|
|
|
|
image.save(f"test_hdr1.jpg", quality=50)
|
|
|
|
|
|
|
|
image = Image.fromarray(ev3)
|
|
|
|
image.save(f"test_hdr2.jpg", quality=50)
|
|
|
|
|
|
|
|
picam2.stop()
|