|
9 | 9 | from picamera2 import Picamera2 |
10 | 10 | from picamera2.encoders import Encoder |
11 | 11 |
|
12 | | -size = (2592, 1944) |
| 12 | +size = (640, 360) |
13 | 13 | picam2 = Picamera2() |
14 | | -video_config = picam2.create_video_configuration(raw={"format": 'SGBRG10', 'size': size}) |
| 14 | +raw = {"format": 'SGBRG10', 'size': size} |
| 15 | +controls = {'FrameRate': 15} |
| 16 | +video_config = picam2.create_video_configuration(raw=raw, controls=controls) |
15 | 17 | picam2.configure(video_config) |
| 18 | +size = video_config['raw']['size'] |
| 19 | +stride = video_config['raw']['stride'] |
| 20 | +print("Size after config:", size, "stride", stride) |
16 | 21 | picam2.encode_stream_name = "raw" |
17 | 22 | encoder = Encoder() |
18 | 23 |
|
19 | | -picam2.start_recording(encoder, 'test.raw', pts='timestamp.txt') |
20 | | -time.sleep(5) |
| 24 | +picam2.start_recording(encoder, '/dev/shm/test.raw', pts='/dev/shm/timestamp.txt') |
| 25 | +time.sleep(3) |
21 | 26 | picam2.stop_recording() |
22 | 27 |
|
23 | | -buf = open("test.raw", "rb").read(size[0] * size[1] * 2) |
24 | | -arr = np.frombuffer(buf, dtype=np.uint16).reshape((size[1], size[0])) |
| 28 | +buf = open("/dev/shm/test.raw", "rb").read(stride * size[1]) |
| 29 | +arr = np.frombuffer(buf, dtype=np.uint8).reshape((size[1], stride)) |
| 30 | +arr = arr[:, :2 * size[0]].view(np.uint16) |
25 | 31 |
|
26 | 32 | # Scale 10 bit / channel to 8 bit per channel |
27 | 33 | im = Image.fromarray((arr * ((2**8 - 1) / (2**10 - 1))).astype(np.uint8)) |
28 | | -im.save("test-8bit.tif") |
| 34 | +im.save("/dev/shm/test-8bit.tif") |
29 | 35 |
|
30 | 36 | # Note - this will look very dark, because it's 10 bit colour depth of image, in |
31 | 37 | # a 16 bit / channel tiff |
32 | 38 | im2 = Image.fromarray(arr) |
33 | | -im2.save("test-16bit.tif") |
| 39 | +im2.save("/dev/shm/test-16bit.tif") |
34 | 40 |
|
35 | 41 | # Create DNG file from frame, based on https://github.com/schoolpost/PiDNG/blob/master/examples/raw2dng.py |
36 | 42 | # Tested loading of DNG in darktable |
|
50 | 56 | t.set(Tag.DNGVersion, DNGVersion.V1_4) |
51 | 57 | t.set(Tag.DNGBackwardVersion, DNGVersion.V1_2) |
52 | 58 | r.options(t, path="", compress=False) |
53 | | -r.convert(arr, filename="test") |
| 59 | +r.convert(arr, filename="/dev/shm/test") |
0 commit comments