RASPICAM_FORMAT_RGB and RASPICAM_FORMAT_BGR swapped
C++ library for controlling Raspberry Pi Camera (with/without OpenCV)
Brought to you by:
ucoava
When running test programs it appears that the formats for RGB and BGR are swapped from what the should be. The offending code is in the Private_Impl::convertFormat (method).
switch ( fmt ) { case RASPICAM_FORMAT_RGB: return MMAL_ENCODING_BGR24; case RASPICAM_FORMAT_BGR: return MMAL_ENCODING_RGB24; case RASPICAM_FORMAT_GRAY: return MMAL_ENCODING_I420;
Note above how RGB format sets ENCODING_BGR24 and visa-versa. I think as some point the MMAL definitions for this were broken but with the current libraspberrypi library these should be swapped. I am using libraspberrypi-1.20160620-1
Here are some related posts from the raspberry pi forums about the change in enum orderings:
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=148432&p=1008664
https://www.raspberrypi.org/forums/viewtopic.php?f=43&t=154059
See new mmal_util_rgb_order_fixed function in https://github.com/raspberrypi/userland/blob/master/interface/mmal/util/mmal_util.c and https://github.com/raspberrypi/userland/blob/master/interface/mmal/util/mmal_util.h
This provides a way to detect the firmware in use and switch the encoding correctly. I can work up a patch if you want. For the moment I have just corrected my version to only work with the latest firmware.
fixed in version 0.1.4