imwrite in android opencv 2.4.10 (Bug #4240)


Added by 祺业 林 almost 10 years ago. Updated almost 10 years ago.


Status:Cancelled Start date:2015-03-16
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-
Affected version:2.4.9 (latest release) Operating System:Android
Difficulty: HW Platform:ARM
Pull request:

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.


ori.png - original img (1.3 MB) 祺业 林, 2015-03-16 03:40 am

QQ图片20150316100624.jpg - second img using write (262.9 kB) 祺业 林, 2015-03-16 03:40 am


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...

Also available in: Atom PDF