>目前我正在尝试将拜耳RGGB数据转换为iplimage。我认为cvtColor可能会起作用,但它需要"垫子"而不是iplimage。
cvtColor(img->imageData, tmpimageData, CV_BayerBG2BGR, 0);
有没有解决方法,也许您可以将拜耳RGGB转换为垫子,然后将垫子转换为iplimage?我真的被这个问题困住了,任何帮助都非常感谢!
OpenCV可以轻松地在Mat和Iplimage之间进行转换。例如,如果img
是IplImage*
:
Mat m(img);
Mat result;
cvtColor(m, result, CV_BayerBG2BGR, 0);
IplImage ipl_result = IplImage(result);
参见 Mat::Mat(const IplImage* img, bool copyData=false) 和 Mat::operator IplImage()
我没有弄清楚为什么cvtColor
不起作用,但我还是找到了为什么使用我的SDK将BayerRGGB转换为RGB。
事实证明,我正在使用的矩阵视觉 SDK 提供了一个内置的解决方案。我需要做的第一件事是将PixelFormat
更改为BayerRG8,以获得8位图像分辨率。之后,我设法通过将idpfRGB888打包到ImageDestination.pixelFormat
中将拜耳RGGB解码为RGB。
此外,我能够以非常原始的方式进行转换,这也完成了工作,但需要太多的 CPU 时间。我循环了我的imageData
阵列,取出了每四个像素。
for (int count_small = 0, count_large = 0; count_large < 1000; count_small += 3, count_large +=4)
{
dest[count_small] = source[count_large];
dest[count_small+1] = source[count_large+1];
dest[count_small+2] = source[count_large+2];
}
不干净,但它完成了工作。