Ask Your Question

Can I get away without converting BGR2RGB in my case ?

asked 2014-04-04 13:11:15 -0500

George Profenza gravatar image

updated 2014-04-04 13:22:20 -0500

I'm working on a little opencv wrapper for the Raspberry PI, mostly using Samarth Brahmbhatt's code from Practical OpenCV.

In his code though he uses YUV encording, merges each channel than converts YUV2BGR. I'm using MMAL_ENCODING_BGR24 in the hope of skipping the conversion step.

Does imshow display BGR matrices as RGB ? My guess was yes, but now I'm slightly confused.

I initialize the cv::Mat with MMAL data like so:

 MMAL_BUFFER_HEADER_T *new_buffer;
   unsigned char* pointer = (unsigned char *)(buffer -> data);
    Mat clr(PiCapture::height, PiCapture::width, CV_8UC3, pointer);

But imshow displays it like so:


I have to do


so imshow displays the image as I expect it(RGB):


My other assumption is, maybe I'm expecting MMAL_ENCODING_BGR24 to return data in BGR and it could be RGB ? (and the cvtColor(clr,clr,BGR2RGB) call has the same result as cvtColor(clr,clr,RGB2BGR): moves the data in the same way, if the images was RGB initially, not BGR, it would get converted to BGR ) ?

In either case, could I somehow initialize a cv::Mat and pass the data in the right format in one go (without converting) ? Is there a way to check the image colour space ?


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-04-12 11:38:43 -0500

George Profenza gravatar image

updated 2014-04-12 18:52:38 -0500

Upgrading to the latest firmware using

sudo rpi-updates

enables an addition encoding mode: MMAL_ENCODING_RGB24 which returns colour frames in the expected format.

For more details see my PiCapture repo

edit flag offensive delete link more

Question Tools


Asked: 2014-04-04 13:11:15 -0500

Seen: 4,794 times

Last updated: Apr 12 '14