Skip to content

Commit 7e3536c

Browse files
committed
cam_test: fix raw handling (metadata, offset) for IMX462
1 parent cf42968 commit 7e3536c

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

depthai-core

utilities/cam_test.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,8 +639,19 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
639639
capture_list.remove(c)
640640
print()
641641
if c.startswith('raw_') or c.startswith('tof_amplitude_') or c.startswith('tof_intensity_'):
642+
# Custom handling for IMX462 that has extra metadata and offset in RAW frame
643+
bits = 10
644+
order = cv2.COLOR_BayerGB2BGR
645+
if pkt.getData().size == 1920*2*(1080+15):
646+
full_raw = pkt.getData()
647+
extra_offset = 384*2
648+
actual_frame = full_raw[(1920*2*15+extra_offset):]
649+
missing_data = np.full(extra_offset, 0xAA, dtype=np.uint8) # FIXME
650+
frame = np.append(actual_frame, missing_data).view(np.uint16).reshape((1080, 1920))
651+
bits = 12
652+
order = cv2.COLOR_BayerGR2BGR
642653
if capture:
643-
filename = capture_file_info + '_10bit.bw'
654+
filename = capture_file_info + f'_{bits}bit.bw'
644655
print('Saving:', filename)
645656
frame.tofile(filename)
646657
# Full range for display, use bits [15:6] of the 16-bit pixels
@@ -649,14 +660,14 @@ def socket_to_socket_opt(socket: dai.CameraBoardSocket) -> str:
649660
if type == dai.ImgFrame.Type.RAW10:
650661
multiplier = (1 << (16-10))
651662
if type == dai.ImgFrame.Type.RAW12:
652-
multiplier = (1 << (16-4))
663+
multiplier = (1 << (16-12))
653664
frame = frame * multiplier
654665
# Debayer as color for preview/png
655666
if cam_type_color[cam_skt]:
656667
# See this for the ordering, at the end of page:
657668
# https://docs.opencv.org/4.5.1/de/d25/imgproc_color_conversions.html
658669
# TODO add bayer order to ImgFrame getType()
659-
frame = cv2.cvtColor(frame, cv2.COLOR_BayerGB2BGR)
670+
frame = cv2.cvtColor(frame, order)
660671
else:
661672
# Save YUV too, but only when RAW is also enabled (for tuning purposes)
662673
if capture and args.enable_raw:

0 commit comments

Comments
 (0)