Name: OpenCVInstall
Download opencv-4.5.2-android-sdk.zip and unzip it.
After that you'll see OpenCV-android-sdk, and we're gonna import this module later
Here I skipped the error message if you import OpenCV by traditional method.
Let's just go to the main task directly
Copy the sdk folder from OpenCV-android-sdk directory
Paste it in the projcet's root directory
Later we're gonna modify setting.gradle for the sdk
Add a string in the bottom: include ':sdk' and then press the sync button in the right top corner
Congratulations on seeing the following information.
Go to File->Project Structure
Click "Dependencies"
Choose "app"
Press the plus sign "+" under Declared Dependencies
Pop up a dialog and choose 3. Module Dependency
Check the sdk and press OK
After that it's going to sync again.
Choose the app and set two versions below
1. Compile Sdk Version
2. Build Tools Version
Do it again for the sdk
You're almost there if you see the BUILD successful
Now We're gonna check if OpenCV modules work well
Go to Logcat, select "Debug" and it's great to see the log "OpenCV installed successfully"
One thing should be noticed even you do such simple stuff like this:
Mat img = new Mat();
You have to make sure that OpenCVLoader has been initialized before you call any OpenCV module.
if (!OpenCVLoader.initDebug())
{
Log.d("OpenCV", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
}
References:
1.https://youtu.be/psoeNfFAKL8 <- The tutorial is good but bad for the way the author expressed
2. How to Integrate OpenCV with Android Studio <- Another way to integrate OpenCV with Android Studio
Besides the Youtuber explains well, you can understand every step why you have to do so.
3. 找不到ndk文件
4. Using setImageDrawable dynamically to set image in an ImageView
留言列表