Skip to content

AndroidMediaNdkCapture pixel format enhancement#26656

Merged
asmorkalov merged 8 commits intoopencv:4.xfrom
warped-rudi:mediandk
Dec 30, 2024
Merged

AndroidMediaNdkCapture pixel format enhancement#26656
asmorkalov merged 8 commits intoopencv:4.xfrom
warped-rudi:mediandk

Conversation

@warped-rudi
Copy link
Copy Markdown
Contributor

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • [ x] There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

…R,BGRA,RGB,RGBA,GRAY)

The output pixel format can now be selected by the user. It defaults to RGB
in order to maintain compatibility with previous versions of the library.

This should fix opencv#26616.
…rty from AndroidMediaNdkCapture

Unsupported or unavailable properties should return -1.
videoWidth(0), videoHeight(0),
videoFrameCount(0),
frameStride(0), frameWidth(0), frameHeight(0),
colorFormat(COLOR_FormatUnknown), fourCC(FOURCC_BGR),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attention: default output become BGR for Android too.

@asmorkalov
Copy link
Copy Markdown
Contributor

@warped-rudi Thanks a lot for the contribution. The BGR->RGB is breaking change. I'll will discuss it with core team and return back. We also have NativeView class based on VideoCapture. Please add color space setter there to prevent wrong colors.

@warped-rudi
Copy link
Copy Markdown
Contributor Author

I think the cause of the problem is the following: From this code here I gather, that the intention is to produce BGR. The reason why we get something like RGB instead is, that the source format is not NV21, but NV12. This is backed by line 514. AndroidMediaNdkVideoWriter basically uses the same hardware accelerator and it's quite unlikely, that different formats get used for encoding and decoding.

@warped-rudi
Copy link
Copy Markdown
Contributor Author

We also have NativeView class based on VideoCapture. Please add color space setter there to prevent wrong colors.

I can't find this class. Where is it?

@asmorkalov
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov self-assigned this Dec 23, 2024
@opencv-alalek
Copy link
Copy Markdown
Contributor

/cc @komakai

@warped-rudi
Copy link
Copy Markdown
Contributor Author

O.K. I see. But this code uses a camera, which means that it instantiates 'AndroidCameraCapture' instead of 'AndroidMediaNdkCapture'. Thus it's unaffected by this change set.

However, with #26627 in place, line 184 can be changed to directly capture BGR4 avoiding the conversion step in line 187.

If you modify the code to read from a file instead from a camera, then you will see the bug reported in #26616 and the effect of this patch.

@asmorkalov
Copy link
Copy Markdown
Contributor

Please also take a look on https://github.com/opencv/opencv/blob/4.x/samples/android/video-recorder/src/org/opencv/samples/recorder/RecorderActivity.java. Looks like we need to set proper output fourcc and drop cvtColor before imwrite.

@komakai
Copy link
Copy Markdown
Contributor

komakai commented Dec 23, 2024

My understanding is that that video capturers should output frames in BGR format, so it appears there is a bug in my original implementation for Android.

@warped-rudi
Copy link
Copy Markdown
Contributor Author

@asmorkalov : The recorder sample is affected. I will have look at it on weekend...

@asmorkalov asmorkalov merged commit d39aae6 into opencv:4.x Dec 30, 2024
@warped-rudi warped-rudi deleted the mediandk branch December 30, 2024 10:22
@asmorkalov asmorkalov mentioned this pull request Jan 15, 2025
shyama7004 pushed a commit to shyama7004/opencv that referenced this pull request Jan 20, 2025
AndroidMediaNdkCapture pixel format enhancement opencv#26656

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
NanQin555 pushed a commit to NanQin555/opencv that referenced this pull request Feb 24, 2025
AndroidMediaNdkCapture pixel format enhancement opencv#26656

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants