I am working with OpenCV library in Android. I have a class which implements PictureCallBack.
The override method onPictureTaken() is as g
opencv has a neat way to writing Mats to files - it can generate different formats based on the file extension provided. Here is a minimal example:
public void writeImageToFile(Mat image, String filename) {
File root = Environment.getExternalStorageDirectory();
File file = new File(root, filename);
Highgui.imwrite(file.getAbsolutePath(), image);
if (DEBUG)
Log.d(TAG,
"writing: " + file.getAbsolutePath() + " (" + image.width()
+ ", " + image.height() + ")");
}
if red and blue is swapped then it sounds like your byte data from onPictureTaken() is in BGRA format. You can swap it to RGBA using:
Imgproc.cvtColor(bgrImg, rgbImg, Imgproc.COLOR_BGR2RGB);
the format is actually device specific - on one device I had it comes through as YUV.