How do I convert Bayer to RGB using OpenCV and vice versa
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);}
Furtherm开发者_StackOverflow中文版ore, I'd like to convert common RGB image to bayer format (let say bilinear) too, whether openCV provide this function as well?
any help would be really appreciated.
Thanks in advance.
Unfortunately OpenCV does not provide BGR to Bayer conversion. Only backward conversion is available.
If you need a conversion to Bayer format then you should implement this conversion yourself or use another library.
精彩评论