1

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 ?

Mahdi Nouri
  • 1,391
  • 14
  • 29

3 Answers3

8

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;
Community
  • 1
  • 1
TouchBoarder
  • 6,422
  • 2
  • 52
  • 60
4

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

Mahdi Nouri
  • 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
3

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.

Daniel Netzer
  • 2,151
  • 14
  • 22