1. Steps
-
Download the opencv package from the official website (I downloaded 4.7.0) and unzip it, openvc official website
-
First create an empty project and simply run it to output helloworld normally.
-
Click
file->new->Import Module
to select the SDk folder in the decompressed opencv-android-sdk folder.
The module name can be changed to the name you want. I changed it to opencv.
4. After loading is complete, look at the picture below. You need to modify some contents in build.gradle under the loaded openCV folder. First 将“kotlin-android”那一句删掉,然后将标号为2,3,4的几个值修改的和主程序中的buidl.gradle中的值一样
, then "try again" to update and modify the internal functions.
- As shown below, click
file->project structure ->Dependencies->app->3 Module Dependency
, then put a check mark on opencv and apply it.
This is basically done. You can load opencv and do a simple test. The code is as follows:
2. Error reporting and modification during the process.
Although the steps are simple, the process is not smooth. I mainly encountered three problems during the process: ① namespace namespace error reporting; ②org.opencv error reporting; ③can't resolve symbol OpenCVEngineInterface
- Namespace error
A simple solution here is to copy the namespace statement in app's build.gradle to opencv's build.gradle. As shown below,
for the second solution, please see below for the third error solution.
- org.opencv reports an error,
justopencv的AndroidManifast.xml中的org.opencv那一句删掉
fix it
3. can't resolve symbol OpenCVEngineInterface
This has really tortured me for a long time. According to what other bloggers said, the org.opencv.engine path configuration is incorrect, which does not solve the problem at all.
The solution is: file->project structure->project, change these two values to 7.1.2 and 7.3 and run again. The namespace error can also be solved in this way
However, it should be noted that I rebuilt a project, modified these two parameters and then re-introduced opencv to succeed. Direct modification when the above error is reported will not work.
3. Reference materials
OpenCV usage tutorial on Android