一、RAW数据
RAW图像就是CMOS或者CCD图像感应器将捕捉到的光源信号转化为数字信号的原始数据。
RAW数据通常不能直接查看内容,需要进行插值等处理,才能进行显示。
二、显示raw图
此时我有一张分辨率为3840*2160,单像素有效数据位宽12bit,拜耳阵列为RGGB的非紧凑型raw图 “12bit.raw”。
“12bit.raw” 图像的大小应为3840 * 2160 * 2 =16588800 字节。
通过以下程序,将raw图在qlabel上显示。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from PyQt5.QtWidgets import QLabel, QWidget, QApplication
import cv2
import numpy as np
from PyQt5 import QtGui
class Demo(QWidget):
def __init__(self):
super().__init__()
self._rgb_arr = None
self.label_img = QLabel(self)
self.label_img.setGeometry(0, 0, 800, 560)
self.label_img.setScaledContents(True)
def image_pixmap(self, image):
Y, X = image.shape[:2]
self._rgb_arr = np.zeros((Y, X, 4), dtype=np.uint8, order='C')
self._rgb_arr[..., 0] = image[..., 2]
self._rgb_arr[..., 1] = image[..., 1]
self._rgb_arr[..., 2] = image[..., 0]
qimage = QtGui.QImage(self._rgb_arr.data, X, Y, QtGui.QImage.Format_RGB32)
pixmap = QtGui.QPixmap.fromImage(qimage)
return pixmap
def show_image(self, width=3840, height=2160, bit=12):
data_type = "uint16"
channels = 1
image = np.fromfile('12bit.raw', dtype=data_type)
if bit >= 8:
image = image >> int(bit - 8)
image = image.reshape(height, width, channels)
img_rgb = cv2.cvtColor(image, cv2.COLOR_BayerRGGB2RGB)
img = self.image_pixmap(img_rgb)
self.label_img.setPixmap(img) # 设置图片显示
self.label_img.setScaledContents(True) # 自适应QLabel大小
if __name__ == '__main__':
app = QApplication(sys.argv)
win = Demo()
win.show()
win.show_image()
sys.exit(app.exec_())
最终显示图像如下: