Android JavaCameraView Image Format NV21 and Conversion to RGB assuming NV12: (Bugfix #3553)


Added by Tim Llewellynn about 11 years ago. Updated almost 11 years ago.


Status:Done Start date:2014-02-16
Priority:Normal Due date:
Assignee:Alexander Smorkalov % Done:

0%

Category:android
Target version:2.4.9
Affected version:2.4.8 (latest release) Operating System:Android
Difficulty:Easy HW Platform:Any
Pull request:https://github.com/Itseez/opencv/pull/2542

Description

Reviewing the source code of JavaCameraView.java (https://github.com/Itseez/opencv/blob/master/modules/java/generator/src/java/android%2BJavaCameraView.java
) for Android there seems to be a mismatch in the color conversion format.

On line 145 the image format is captured using NV21: params.setPreviewFormat(ImageFormat.NV21);

On line 291 the image is converted assuming it is captured using NV12 : Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2BGR_NV12, 4);

Is this correct?

Imgproc.cvtColor(mYuvFrameData, mRgba, Imgproc.COLOR_YUV2BGR_NV12, 4);


Associated revisions

Revision d17740ec
Added by Alexander Smorkalov almost 11 years ago

Bug #3553 JavaCameraView frame format and cvtColor format inconsistency fixed.

History

Updated by Kirill Kornyakov about 11 years ago

Alexander, could you please check it?

  • Assignee set to Alexander Smorkalov
  • Category set to android
  • Target version set to 2.4.9

Updated by Kirill Kornyakov about 11 years ago

  • Status changed from New to Open

Updated by Kirill Kornyakov about 11 years ago

  • Tracker changed from Bug to Bugfix

Updated by Alexander Smorkalov about 11 years ago

This inconsistency in color spaces is not issue actually. Java uses big-endian byte order. Native code on ARM uses little-endian byte order. NV12 and NV21 differs in order U and V component. So usage of NV12 conversion compensates byte order issue. So we do not need to do change conversion type, but may be add check and uses different conversions (http://developer.android.com/reference/java/nio/ByteOrder.html). Also comments in code will be usefull too.

Updated by Alexander Smorkalov about 11 years ago

  • Pull request set to https://github.com/Itseez/opencv/pull/2413
  • Difficulty set to Easy

Updated by Alexander Smorkalov almost 11 years ago

I made a mistake in the previous statement. byte order in yuv frame does not depend on Java virtual mashine. It looks like OpenCV uses invalid color conversion. It looks the same but still invlid. The new pull request fixes the issue.

  • Pull request changed from https://github.com/Itseez/opencv/pull/2413 to https://github.com/Itseez/opencv/pull/2542

Updated by Alexander Smorkalov almost 11 years ago

  • Status changed from Open to Done

Also available in: Atom PDF