i'm using imageComparator to compare two images with OpenCV library but i can't import DMatch class in my app org.opencv.features2d.DMatch
any one knows how should i fix this problem ?

- 1,391
- 14
- 29
-
did you added the entire ImageComparator lib to your project? – Daniel Netzer Jan 03 '16 at 16:34
-
@DanielNetzer yeah all of it,the problem is from OpenCV library – Mahdi Nouri Jan 03 '16 at 16:56
-
do you have a log of some sort? a code you can share to ease things up abit for us yo try and help you better? – Daniel Netzer Jan 03 '16 at 16:58
-
on what ADT are you working on? – Daniel Netzer Jan 03 '16 at 17:02
-
@DanielNetzer i'm working with Android Studio,DMatch class is gone from my OpenCV library that's why it gave's me error.i think they've remove it in the new version of the library – Mahdi Nouri Jan 03 '16 at 17:04
-
how do you add OpenCV libs in the gradle? – Daniel Netzer Jan 03 '16 at 17:11
-
@DanielNetzer you should import it from "import module" in FILES>IMPORT MODULE – Mahdi Nouri Jan 03 '16 at 17:13
3 Answers
I got the imageComparator project working in Android Studio with openCV 3.1 by following this SO answer
and to fix the failed to import
error replace:
import org.opencv.features2d.DMatch;
with
import org.opencv.core.DMatch;

- 1
- 1

- 6,422
- 2
- 52
- 60
well finally I've found my answer by my self :D
if you guys have this problem too u should download OpenCV library version 2.4.9
EDIT
if you are using newer versions the package name is changed to core

- 1,391
- 14
- 29
-
then dont mark it as an answer, but what lib version did you used? and why not try and implement the latest version of opencv? – Daniel Netzer Jan 03 '16 at 18:46
-
@DanielNetzer i was using the last version but in that version DMatch class is removed so you can't use imageComparator but in the old versions (2.4.9) you can find DMatch... – Mahdi Nouri Jan 03 '16 at 18:51
-
https://github.com/Itseez/opencv/search?utf8=%E2%9C%93&q=DMatch According to github testcode for OpenCV latest version DMatch is still a valid class. but if that works, it works. – Daniel Netzer Jan 03 '16 at 18:56
so after a quick research you are right implementing OpenCV with Android Studio requires a few steps to actually get it working properly.
Adding OpenCV to your new project
- Create a folder called “libraries” inside your Android Studio project, and copy there entire content of sdk/java out of your OpenCV Android folder.
- Rename that folder to “opencv”, so that you will end up having your Android Studio project with subfolder “libraries/opencv”.
Now, inside this “opencv” folder, create a build.gradle file, with the following content:
apply plugin: 'android-library'
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.3.0' } }
android { compileSdkVersion 23 buildToolsVersion "23.0.1"
defaultConfig { minSdkVersion 8 targetSdkVersion 23 versionCode 3000 versionName "3.0.0" }
sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] res.srcDirs = ['res'] aidl.srcDirs = ['src'] } } }
** Weird bug Code tag change indentation on the code.
Edit your settings.gradle file in your application’s main directory and add this line:
include ':libraries:opencv'
Open Android Studio
- Do this in Android Studio: Tools/Android/Sync Project with Grade files Go to File/Project Structure, inside Modules pick your ‘app’, then from the Tab pick: Dependencies, click + to add new dependency, pick Module Dependency, and add :library:opencv dependency to your project. Click OK.
- Create a jniLibs folder in the /app/src/main/ location and copy the all the folder with *.so files (armeabi, armeabi-v7a, mips, x86) in the jniLibs from the OpenCV Android SDK/native/libs folder.
- Make sure that you do have Android SDK 19 installed (as per above gradle files), or use a version that you have installed.
- Try to sync Gradle again, after adding the dependency. You may need to delete section “android” from your top-level build.gradle if the sync complains.
- Build the project.
Source :: https://blog.hig.no/gtl/2015/10/01/android-studio-opencv/
EDIT 1:
https://www.youtube.com/watch?v=OTw_GIQNbD8 - Youtube video with all the steps required to do from scratch by Md. Zakir Hossen.

- 2,151
- 14
- 22
-
@PHELAT if this answer helped you I would appreciate you marking it as an answer. – Daniel Netzer Jan 03 '16 at 18:02
-
well thank you for your answer but this is not my answer i have imported this library successful – Mahdi Nouri Jan 03 '16 at 18:43