Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How do I capture, process and output an image in RGB (not BGR)?

I have read that opencv captures images in BGR rather than RGB. In my first experiments I am capturing a video image and output it as follows:

(C++ code snippet - error checking and control flow left out for clarity):

Mat frame;
VideoCapture capture(0);

capture >> frame;
/* some processing code here*/
imshow(window_name, frame);

The code works except that the capture works in BGR and the output of imshow() is RGB which means that the red and blue channels are swapped in the display.

So... I can work with data in BGR but I would like to know if it is possible to a) capture in RGB (like raspistill does) or b) convert to RGB before display without a nested loop to convert each pixel?

(This is running on a Raspberrry Pi with opencv 2.3.1 and the Video4Linux2 Driver v1.9.8 in case it makes any difference).