问题描述
我一直在努力弄清楚如何使用opencv去马赛克功能。我已经安装了带有CUDA支持的OpenCV 4.4.0,并且到目前为止,我认为我需要做的是:
这是我拥有的代码段。
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位内部,因此处理起来要容易得多。