Issue
The fact that this question is still occasionally getting new upvotes makes me think I'm not the only one in this kind of situation, so I've decided to write a step by step explanation of what worked for me in hope that others might find it useful in the future. Everything is based on this video, but I think it's better to write a proper guide here in case it gets taken down.
If you're looking for help with OpenCV 3.4, this is what I was following before trying version 4.5.
Solution
This is the complete procedure that currently works for me with OpenCV 4.5.2 on Android Studio 4.1.3.
- In your project click on
File > New > Import Module...and select the/sdkdirectory inside your OpenCV download. Give it a meaningful name and wait for the procedure to finish: the directory you selected should have been copied in the root of your project where the default/appdirectory resides; - open the Project Structure (for example by clicking on
File > Project Structure...), then go toDependencies(on the left), click onappand on the+icon in theDeclared Dependenciestab (not the one in theModulestab); - click on
Module Dependencyand select the checkbox for the OpenCV SDK that you imported earlier. You should now see it in the list with the other dependencies, so click onApplyandOKto exit from the Project Structure; - open the
build.gradlefile of your app module, copy the values ofcompileSdkVersion,minSdkVersionandtargetSdkVersion, then paste them in thebuild.gradlefile of the OpenCV module replacing the default ones so they match exactly. You can also update thesourceCompatibilityandtargetCompatibilityfields toJavaVersion.VERSION_1_8; - finally, sync your project with Gradle files.
To check if it works, add this snippet to your code, for example in MainActivity:
if (OpenCVLoader.initDebug()) {
Log.d("myTag", "OpenCV loaded")
}
Answered By - rdxdkr
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.