The Road to Android Studio Development (5) Importing OpenCV and Resolving Errors

1. Steps

  1. Download the opencv package from the official website (I downloaded 4.7.0) and unzip it, openvc official website

  2. First create an empty project and simply run it to output helloworld normally.
    Insert image description here

  3. Click file->new->Import Moduleto select the SDk folder in the decompressed opencv-android-sdk folder.

Here is the quote

Here is the quote

Here is the quoteThe 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.

Here is the quote

  1. As shown below, click file->project structure ->Dependencies->app->3 Module Dependency, then put a check mark on opencv and apply it.

Here is the quote

Here is the quote

This is basically done. You can load opencv and do a simple test. The code is as follows:
Insert image description here

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

  1. Namespace error

Here is the quote

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.

  1. org.opencv reports an error,
    just opencv的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

Here is the quote

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

OpenCV library installation

Android uses OpenCV to process images

Guess you like

Origin blog.csdn.net/qq_41104439/article/details/132479459