imwrite in android opencv 2.4.10 (Bug #4240)
Description
i don't really know how to decribe this problem.
I capture preview from camera using JavaCameraView.And i get the preview data as Mat from public Mat onCameraFrame(CvCameraViewFrame inputFrame) callback.
i want to save the preview data as a file when needed.The problem occured! if i use Highgui.imwrite to save as jpg or png,color will change.but if i use the following code,it is ok
Bitmap bitmap = Bitmap.createBitmap(m.cols(), m.rows(), Bitmap.Config.ARGB_8888);
org.opencv.android.Utils.matToBitmap(m,bitmap);
saveBitmap(fileOutputStream,bitmap);
i upload the result picture as attachment.
History
Updated by Alexander Smorkalov almost 10 years ago
The default color image layout for Android is RGBA. The default layout for OpenCV color image is BGR. Java bindings are just wrappers for native C++ code and inherit this behavior. So it's expected that Highgui.imwrite
produces invalid frame. It interpret image in wrong way and swap color channels.
We cannot change library behavior and change default image layout as it affects all platforms and a lot of color-dependent functions. So the only solution is convert image from RGB to BGR.
- Status changed from New to Cancelled
Updated by Andrey Pavlenko almost 10 years ago
From the very beginning Android-specific Mat2Bitmap
and Bitmap2Mat
functions could make RGBA <-> BGRA
conversion since all the OpenCV API assumes BGR colors order, but historically they don't.
It can be improved now by adding 2 more functions, say MatBGR2Bitmap
and Bitmap2MatBGR
and recommending using them instead.
Let me or somebody else propose such a patch...