I have read at several places (source, source) that OpenCV uses BGR color format by default.
But I am writing a class to detect a blob of a certain color (red) in an image (following the Color Blob Detection sample). So in the onCameraFrame(CvCameraViewFrame inputFrame)
function, we return the value inputFrame.rgba()
. According to the documentation,
rgba() This method returns RGBA Mat with frame
So I assumed that my rgbaFrame
, which is the variable storing the value of inputFrame.rgba()
in my program, contains the Mat in RGBA format.
But when I run the app, the red color in the original image appeared to be bluish in the rgbaFrame
Mat I wrote to the external SD card. So apparently, the Mat is in BGR format, because red is appearing to be blue. (This is discussed in the comments of this question.)
So I changed my cvtColor
function from
Imgproc.cvtColor(rgbaFrame, hsvImage, Imgproc.COLOR_RGB2HSV_FULL);
to
Imgproc.cvtColor(rgbaFrame, hsvImage, Imgproc.COLOR_BGR2HSV_FULL);
But nothing changed when I run the program. Red in original image still appears blue in the captured frame.
So now I am looking for a way to convert RGB to BGR format, to try and see if that helps solve my problem. But have failed to find one. How do I convert BGR to RGB? Please share if you have any other suggestions for me.
- original screenshot from which camera frame is captured:
- rgbaFrame.jpg (because I did
Highgui.imwrite("/mnt/sdcard/DCIM/rgbaFrame.jpg", rgbaFrame);//check
)