使用opencv进行解马赛克

问题描述

我一直在努力弄清楚如何使用opencv去马赛克功能。我已经安装了带有CUDA支持的OpenCV 4.4.0,并且到目前为止,我认为我需要做的是:

  1. 读取原始图像数据
  2. 将原始图像数据加载到Mat对象
  3. 将Mat数据上传到GpuMat(主机到设备的上传
  4. 动植物
  5. 将GpuMat数据(用于主机下载的设备)下载到Mat对象
  6. 显示或写出结果

这是我拥有的代码段。

ifstream ifs("image.raw",ios_base::binary);
ifs.read(buffer,length);
// snip ...buffer contains the entire file...

Mat src_host(6464,4860,CV_16UC1,buffer);
GpuMat dst,src;
src.upload(src_host);

// Debayer here
cv::cuda::demosaicing(src,dst,COLOR_BayerRG2BGR);

// have a look
Mat result_host;
dst.download(result_host);

namedWindow("Debayered Image",WINDOW_KEEPRATIO);
resizeWindow("Debayered Image",6464/5,4860/5);
imshow("Debayered Image",result_host);
waitKey(0);

我有来自摄像机的原始帧,每像素12位,RGGB,尺寸为6464 x4860。我不确定如何为OpenCV指定宽度和高度,为它指定什么CV_TYPE,是否为正确读取和上传数据以进行去马赛克,为演示提供什么颜色的COLOR_code,以及如何下载结果以显示和保存到文件中(最好是编写png或类似文件的高级例程)。

有人知道我是否在正确的轨道上吗?

谢谢!詹姆斯

解决方法

是的,我在正确的轨道上。行和列被意外交换,因此更正后的代码为:

ifstream ifs("image.raw",ios_base::binary);
ifs.read(buffer,length);
// snip ...buffer contains the entire file...

Mat src_host(4860,6464,CV_16UC1,buffer);
GpuMat dst,src;
src.upload(src_host);

// Debayer here
cv::cuda::demosaicing(src,dst,COLOR_BayerRG2BGR);

// have a look
Mat result_host;
dst.download(result_host);

namedWindow("Debayered Image",WINDOW_KEEPRATIO);
resizeWindow("Debayered Image",4860/2,6464/2);
imshow("Debayered Image",result_host);
waitKey(0);

虽然传感器数据为12位,但是每12位位于16位内部,因此处理起来要容易得多。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...