Android camera tutorial update #24692
This PR extends the OpenCV 4 Android tutorial by a simple camera app based on existing code.
This part was accidentally removed during the #24653 preparation, this PR restores it and aligns it to the latest Android Studio.
### 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
@ -55,7 +55,7 @@ Here's how to get a ready to work environment:
2. Extract the tar.gz archive
3. Follow the instructions in `Install-Linux-tar.txt`: open `android-studio/bin` folder in terminal and run `./studio.sh`
4. Perform standard installation through GUI
5. Optionally you can add a shortcut on a desktop for a quick access by clicking menu Tools -> Create desktop entry. The menu appears after any project is created or opened.
5. Optionally you can add a shortcut on a desktop for a quick access by clicking menu ***Tools -> Create desktop entry***. The menu appears after any project is created or opened.
2. Install fresh Android SDK and NDK:
1. Open SDK manager in Android Studio (***Customize -> All Settings -> Languages & Frameworks -> Android SDK***)
@ -29,6 +29,8 @@ If you encounter any error after thoroughly following these steps, feel free to
Hello OpenCV sample
-------------------
In this section we're gonna create a simple app that does nothing but OpenCV loading. In next section we'll extend it to support camera.
In addition to this instruction you can use some video guide, for example [this one](https://www.youtube.com/watch?v=bR7lL886-uc&ab_channel=ProgrammingHut)
1. Open Android Studio and create empty project by choosing ***Empty Views Activity***
@ -75,7 +77,6 @@ In addition to this instruction you can use some video guide, for example [this
6. OpenCV project uses `aidl` and `buildConfig` features. Please enable them in
`MyApplication/OpenCV/build.gradle` file to `android` block:
@code{.gradle}
buildFeatures{
aidl true
@ -93,17 +94,19 @@ In addition to this instruction you can use some video guide, for example [this
8. Before using any OpenCV function you have to load the library first. If you application includes other OpenCV-dependent native libraries you should load them ***after*** OpenCV initialization.
Library is loaded at app start:
Add the folowing code to load the library at app start:
@ -111,3 +114,84 @@ In addition to this instruction you can use some video guide, for example [this
9. Choose a device to check the sample on and run the code by pressing `run` button
![](images/run_app.png)
Camera view sample
------------------
In this section we'll extend our empty OpenCV app created in the previous section to support camera. We'll take camera frames and display them on the screen.
1. Tell a system that we need camera permissions.
Add the following code to the file `MyApplication/app/src/main/AndroidManifest.xml`: