Download OpenCV4AndroidSdk
- If you have not done so, download OpenCV4Android from this website https://sourceforge.net/projects/opencvlibrary/files/opencv-android/
- Extract the files into a folder e.g. /path/to/Open-CV-android-sdk/
- Run Android Studio. Choose Create a New Project.
- In the Create New Project dialog box, toggle on Include C++ support.
- Choose appropriate options and click Next in the following screens.
- Click Finish.
The new project is created.
- In the Android Studio File menu, select File | New | Import Module.
The Import Module from Source dialog box appears. - In the Source directory field, click the ... button and browse to the downloaded OpenCV4Android files and select the java folder e.g. /path/to/OpenCV-android-sdk/sdk/java/.
- Optional. In the Module name field, type in a name e.g. :opencv.
- Click Next and Finish.
The module is imported (with most likely error messages) - Options. You can download the missing dependencies by clicking the Install missing platforms and sync project link. Or you can edit the OpenCV4Android's build.gradle file to enter the installed dependencies.
- In Android Studio, open up the file build.gradle from the imported module opencv module e.g. /path/to/opencv/build.gradle. It may be necessary to change the Project pane to display as project view.
- In the editor, changed the compiledSdkVersion to 27 (or any installed version), the targetSdkVersion to 27 (or any installed version).
- Then sync the gradle project.
The project is synced but now there is an error about the manifest file. - Open up the manifest file /path/to/opencv/src/main/AndroidManifest.xml in the editor.
- Now, comment out the uses-sdk line as shown in the screenshot above.
- Sync the project again.
The OpenCV module is successfully configured.
- In Android Studio, select App in the Project pane.
- Select File | Project Structure.
The Project Structure dialog box appears. - Select app. Then click the Dependencies tab. Click +. Choose module dependency.
- Choose the imported Opencv module.
OpenCV is appended to the list. - Click OK.
The module is added the Android App project.
- Open up a File Explorer. Select all the native platform folders under the /path/to/OpenCV-android-sdk/sdk/native/libs/*.
- Right click and select Copy.
- In Android Studio, right click on the app folder (in project view). Choose Paste.
The Copy dialog box appears. - In the To directory field, change the text to /path/to/myandroid/app/jniLibs/.
- Click OK.
The native binaries are copied to the project. - To enable the Android project to know where the native binaries are, open up the app's build.gradle file in the editor.
- Add in the android class, add in the following sourceSets lines:
Note: 'jniLibs' means the jniLibs directory relative to this build.gradle file location.sourceSets { main { jniLibs.srcDirs = ['jniLibs'] } }
- Sync the project.
No comments:
Post a Comment