我目前正在尝试将一个8位原始彩色图像转换为8位RGB。我得到了一个通道错误,它期望Bayer是1个通道。
我正在使用下面的代码。
if (convertBayerChckBox->Checked)
{
try{
cv::Mat temp(imgOriginal.rows, imgOriginal.cols, CV_8UC3);
imgOriginal.copyTo(temp);
cv::cvtColor(temp, imgOriginal, CV_BayerRG2BGR);
}
catch (const cv::Exception& ex)
{
std::cout << "EXCEPTION: " << ex.what() << std::endl;
errLog << "EXCEPTION: " << ex.what() << std::endl;
}
}然后我在函数cv::cvtColor中得到以下异常: exception:......\modules\imgproc\src\color.cpp:4194: error:(-215) scn == 1 && dcn == 3
我不知道如何从拜耳转换到RGB
发布于 2015-11-17 22:19:48
您需要将input Mat的数据指针设置为目标指针。以下是将您的拜耳图像转换为RGB的示例程序。这里我使用了一个文件中的buffer。您可以使用摄影机帧缓冲区。希望这能有所帮助!
Mat mSource_Bayer(Size(m_IWidth,m_IHeight),CV_8UC1);
Mat mSource_Bgr(Size(m_IWidth,m_IHeight),CV_8UC3);
FILE *fp = NULL;
uchar *imagedata = NULL;
int framesize = m_IWidth * m_IHeight;
//Open raw Bayer image.
fp = fopen(FileName_S.c_str(), "rb");
//Memory allocation for bayer image data buffer.
imagedata = (uchar*) malloc (sizeof(uchar ) * framesize);
//Read image data and store in buffer.
fread(imagedata, sizeof(uchar ), framesize, fp);
mSource_Bayer.data= imagedata;
fclose(fp);
int Selection= m_BayerFormat.GetCurSel();
if(Selection==0)
cvtColor(mSource_Bayer, mSource_Bgr, CV_BayerBG2BGR);//Perform demosaicing process
else if(Selection==1)
cvtColor(mSource_Bayer, mSource_Bgr, CV_BayerGB2BGR);//Perform demosaicing process
else if(Selection==2)
cvtColor(mSource_Bayer, mSource_Bgr, CV_BayerRG2BGR);//Perform demosaicing process
else if(Selection==3)
cvtColor(mSource_Bayer, mSource_Bgr, CV_BayerGR2BGR);//Perform demosaicing process
imshow("mSource_Bgr",mSource_Bgr);发布于 2018-06-28 14:07:02
此外,为了执行拜耳到RGB的转换,我建议使用Simd Library中的函数SimdBayerToBgr。它的功能似乎比它的模拟从OpenCV (它使用AVX2和AVX512)更快。
https://stackoverflow.com/questions/33756723
复制相似问题