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;
mmal_buffer_header_mem_lock(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
cvtColor(clr,clr,BGR2RGB);
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) ?
Thanks