These are the steps that worked for me.
- Go to the OpenCV releases page and click on Android pack link of the current version section (https://opencv.org/releases.html). I used 4.1.1
- Unzip the file named opencv--android-sdk
- In Android Studio, go to File > New > Import Module... and the choose /sdk and wait for the sync to finish.
- Include open-cv as a module dependency. File -> Project Structure.
- Select the project module(not the open-cv module we added in step 3)
- Add the opencv as a module dependency.
- Check in the build.gradle file is it has been added as a dependency.
- Clean and build the project.
NOTEs
- Do not import /sdk/java like most tutorials suggest.
- You do not have to copy the native libraries into your project like most tutorials suggest.
Once you have OpenCV imported, use this tutorial to get the preview to fill the preview window.
And then use this version of the JavaCamera2View. JavaCamera2View uses the camera2 api.
These are the steps that worked for me, happy to be corrected if I have done something wrong.
Good Luck :)