Demosaicing/Coloring a bayer bggr image with openCV

2.1k views Asked by At

I am working with a custom USB camera which sends raw Bayer BGGR 16 bit/pixel images. I have a C++ project which is able to show the camera stream in grayscale, but when I try to use any of the OpenCV's built in color conversion function I always got misscolored images. I checked the camera picture and also with the sensor test pattern feature. I tried demosaicing the picture manually, only got greenish distorted pictures. I tried to learn more about the bayer/raw images, but now I am a bit stuck and would be glad for any kind of help or hint. It is also looks strange for me, when I check the type and channels of the input videocapture frame It has 8bit 3 channel, even if try to turn of the RGB conversion. I attached the actuall outputs.

Grayscale test pattern:

enter image description here

COLOR_BayerRG2RGB:

enter image description here

Manual demosaic:

enter image description here

Gray camera picture:

enter image description here

COLOR_BayerRG2RGB:

enter image description here

Manual demosaic:

enter image description here

1

There are 1 answers

1
wohlstad On

Try cv::COLOR_BayerGB2BGR instead of cv::COLOR_BayerRG2RGB.

OpenCV supports 4 bayer patterns:

COLOR_BayerBG2BGR
COLOR_BayerGB2BGR
COLOR_BayerRG2BGR
COLOR_BayerGR2BGR

So either your pattern (BGGR) correlates to cv::COLOR_BayerGB2BGR, or it could be that you actually have one of the other patterns.

Anyway a quick test will determine it.