V4L2 10bit像素存储机制疑问及RAW数据解析求助
10bit RAW图像存储格式疑问
背景与预期存储格式
根据V4L2的10bit传感器文档,我原本认为单个10bit像素的存储格式应该是:
xxxxxxxx 000000xx
其中前8位是低字节,后8位是高字节,且高字节的前6位为0。
数据采集方式
我在Jetson Xavier NX上使用以下命令获取传感器数据:
v4l2-ctl -d /dev/video0 --set-fmt-video=width=1280,height=720,pixelformat=RG10 --set-ctrl=bypass_mode=0 --stream-mmap --stream-count=1 --stream-to=file.raw
数据读取代码
以下是读取RAW文件并打印数据及二进制形式的Python代码:
import numpy as np raw_file_path = 'file.raw' width = 3280 height = 2464 dtype = np.uint16 with open(raw_file_path, 'rb') as f: data = np.fromfile(f, dtype=dtype) if data.size != width * height: raise ValueError(f"File size doesn't match expected shape ({height}, {width}). Got {data.size} elements.") image = data.reshape((height, width)) # shape (3280, 2482) print(image) print(image.shape) print(image.dtype) image_bin = np.vectorize(lambda x: format(x, '016b'))(image) print(image_bin) print(image_bin.shape) print(image_bin.dtype)
输出结果
运行代码后得到的输出如下:
[[4548 4996 4484 ... 4676 4932 4612] [5125 4420 4996 ... 0 0 0] [4676 5125 4484 ... 4612 5060 4548] ... [4676 4356 4676 ... 0 0 0] [4164 4420 4292 ... 4292 4548 4292] [4420 4292 4420 ... 0 0 0]] (2464, 3280) uint16 [['0001000111000100' '0001001110000100' '0001000110000100' ... '0001001001000100' '0001001101000100' '0001001000000100'] ['0001010000000101' '0001000101000100' '0001001110000100' ... '0000000000000000' '0000000000000000' '0000000000000000'] ['0001001001000100' '0001010000000101' '0001000110000100' ... '0001001000000100' '0001001111000100' '0001000111000100'] ... ['0001001001000100' '0001000100000100' '0001001001000100' ... '0000000000000000' '0000000000000000' '0000000000000000'] ['0001000001000100' '0001000101000100' '0001000011000100' ... '0001000011000100' '0001000111000100' '0001000011000100'] ['0001000101000100' '0001000011000100' '0001000101000100' ... '0000000000000000' '0000000000000000' '0000000000000000']] (2464, 3280) <U16
疑问
从输出的二进制数据中看不到预期的连续6个零,请问10bit图像实际是如何存储的?
内容的提问来源于stack exchange,提问作者Talha Tahir
相关产品推荐
相关产品推荐

