问题描述
OpenCV 提供了将 Bayer 转换为 RGB 的函数,但是如何使用这个 CV_BayerBG2BGR 和其他类似的函数?我使用了下面的代码,但错误显示为无效频道号.由于我使用 RGB 图像作为 originalImage,那么这个函数实际上是如何工作的?
OpenCV provided function to convert Bayer to RGB, but how to use this CV_BayerBG2BGR , and other similar function?I used code below, but the error appears stated invalid channel number. Since I use RGB image as originalImage, anyway how this function actually works?
void main(){
// Declare and load the image
// Assume we have sample image *.png
IplImage *originalImage = cvLoadImage("bayer-image.jpg",-1);
// The image size is said to be 320X240
IplImage *bayer2RGBImage;
bayer2RGBImage = cvCreateImage(cvSize(100,100),8,3);
cvCvtColor(originalImage,bayer2RGBImage,CV_BayerBG2BGR);
//Save Convertion Image to file.
cvSaveImage("test-result.jpg",bayer2RGBImage);
//Release the memory for the images that were created.
cvReleaseImage(&originalImage);
cvReleaseImage(&bayer2RGBImage);}
另外,我也想把普通的RGB图像转换成bayer格式(比如双线性),openCV是否也提供这个功能?
Furthermore, I'd like to convert common RGB image to bayer format (let say bilinear) too, whether openCV provide this function as well?
任何帮助将不胜感激.
提前致谢.
推荐答案
遗憾的是 OpenCV 不提供 BGR 到 Bayer 的转换.只能向后转换.
Unfortunately OpenCV does not provide BGR to Bayer conversion. Only backward conversion is available.
如果您需要转换为 Bayer 格式,那么您应该自己实现此转换或使用其他库.
If you need a conversion to Bayer format then you should implement this conversion yourself or use another library.
这篇关于如何使用 OpenCV 将 Bayer 转换为 RGB,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!