The Wayback Machine - https://web.archive.org/web/20210404104624/https://github.com/opencv/opencv/pull/19597
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android NDK camera support #19597

Merged
merged 4 commits into from Feb 25, 2021
Merged

Android NDK camera support #19597

merged 4 commits into from Feb 25, 2021

Conversation

@komakai
Copy link
Contributor

@komakai komakai commented Feb 22, 2021

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 other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work

This PR fixes #11952

Add an Android native camera capture backend to the videoio module.
Based loosely on https://github.com/android/ndk-samples/tree/main/camera
Requires Android native API level 24 or above (in order to access NDK camera APIs)

android_pack_config=ndk-18-api-level-24.config.py
@alalek alalek added this to the 4.5.2 milestone Feb 24, 2021
@alalek alalek self-requested a review Feb 24, 2021
@alalek
alalek approved these changes Feb 25, 2021
Copy link
Contributor

@alalek alalek left a comment

Well done! Thank you for contribution 👍

@alalek alalek self-assigned this Feb 25, 2021
@alalek alalek merged commit 0553543 into opencv:master Feb 25, 2021
4 of 6 checks passed
4 of 6 checks passed
OpenCV CN Ubuntu 18.04 x86-64 Build finished.
Details
OpenCV CN Ubuntu 20.04 arm64 Build finished.
Details
OpenCV CN RISC-V Build finished.
Details
OpenCV CN RISC-V with RVV Build finished.
Details
OpenCV CN Windows 10 x64 Build finished.
Details
default Required builds passed
Details
@jumpy88
Copy link

@jumpy88 jumpy88 commented Feb 26, 2021

So, should now with this update cv::VideoCapture.open(0) succeed and return an handle to accede a camera on Android? Does it only work for internal cameras or also for USB cameras? (Camera2 API I understand this patch is based on should support USB cameras https://source.android.com/devices/camera/external-usb-cameras)

@komakai
Copy link
Contributor Author

@komakai komakai commented Feb 27, 2021

@jumpy88 it will work for any device that is accessible to the Android NDK Camera API (https://developer.android.com/ndk/reference/group/camera)

(Camera2 API I understand this patch is based on should support USB cameras https://source.android.com/devices/camera/external-usb-cameras)

This link is aimed at device manufacturers who are building the Android OS itself, not general Android app developers. (Also note: Camera2 is a Java API whereas the OpenCV videoio module is written in C++)

@jumpy88
Copy link

@jumpy88 jumpy88 commented Mar 5, 2021

@komakai Ops, sorry, I thought Camera2 was an API for developers and it was accessible in Android NDK. My knowledge about Android is still very poor. Ok, I'll give it a try with your code and will post the result.
Thank you for your contribution and support.

@jumpy88
Copy link

@jumpy88 jumpy88 commented Mar 25, 2021

Hi, I've just done some experiments with 2e2df44 commit in a Godot Engine proof of concept. It works with built-in cameras but doesn't seem to recognize external USB cameras. The only weird thing is sometimes the visualized frame appears having blue and red channels swapped, but I don't have enough information to open an issue (I don't know if it's due to OpenCV itself or is my fault). You can find the sample code here https://github.com/jumpy88/godot_ocv-camera-reader
Thank you for the great job @komakai

}
return true;
case CV_CAP_PROP_CONVERT_RGB:
convertToRgb = (value != 0);

This comment has been minimized.

@alalek

alalek Mar 25, 2021
Contributor

cv::cvtColor(yuv, out, convertToRgb ? cv::COLOR_YUV2RGB_YV12 : cv::COLOR_YUV2BGR_YV12);

BTW, meaning of this property is different (name misleads unfortunately, it is not BGR / RGB switch):

  • CV_CAP_PROP_CONVERT_RGB = 1 (default): VideoCapture returns frames as "BGR" 8UC3 cv::Mat.
  • CV_CAP_PROP_CONVERT_RGB = 0: VideoCapture returns frames in other formats, like NV12, Y8, etc (format is retrieved and/or sometimes specified through CAP_PROP_FOURCC)

This comment has been minimized.

@komakai

komakai Mar 26, 2021
Author Contributor

@alalek OK thanks for the explanation - will prepare a fix for this when I get a minute.

This comment has been minimized.

@splinterwhatever

splinterwhatever Mar 26, 2021

Is there a space in the api to allow for the BGR/RGB switch in addition to the correct convertToRGB behaviour?

cheers, Jeff

@komakai komakai mentioned this pull request Apr 4, 2021
3 of 3 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked issues

Successfully merging this pull request may close these issues.

4 participants