Surf Image Matching problem

1,304 views
Skip to first unread message

Francesco Lupia

unread,
Oct 29, 2011, 1:06:54 PM10/29/11
to android...@googlegroups.com
Hello guys,

I'm trying to build an application that uses OpenCV SURF (Speeded Up Robust Features) descriptors in order to get same points between 2 images.
I'm using the find_obj.cpp demo which I modified to fit my needs. So let's say i have my jni_part.cpp where I used the find_obj.cpp code and i am able to compile it through the ndk-build command, lib folder is generated and it is correctly placed in the apk file.

Here is the problem: when i try to run the project on my android phone (os version 2.3) i always get this error:

ERROR/AndroidRuntime(3342): java.lang.ExceptionInInitializerError
Caused by: java.lang.UnsatisfiedLinkError: Couldn't load opencv: findLibrary returned null

this is my Android.mk:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

OPENCV_CAMERA_MODULES:=off
include ../includeOpenCV.mk
ifeq ("$(wildcard $(OPENCV_MK_PATH))","")
    #try to load OpenCV.mk from default install location
    include $(TOOLCHAIN_PREBUILT_ROOT)/user/share/OpenCV/OpenCV.mk
else
    include $(OPENCV_MK_PATH)
endif

LOCAL_MODULE    := opencv
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_LDLIBS +=  -llog -ldl

include $(BUILD_SHARED_LIBRARY)

and of course in my activity class i have:

static{
        System.loadLibrary("opencv");
    }

I have uploaded my jni_part.cpp since i don't really know if that is the problem, but i guess not. I know my code there is really ugly since it is a test and maybe it doesn't even work because i couldn't try it. You can see here what i want to achieve: http://www.youtube.com/watch?v=-TkssDoNJS4

Feel free to give me any suggestion to sort things up.

p.s. i have already tried to run the application with both 2.1 and 2.2 os on a real device and i tried even on the emulator but i get always the same error.

Thank you guys, i really hope you can help me.
jni_part.cpp
bmpfmt.h

Andrey Pavlenko

unread,
Oct 31, 2011, 7:46:22 AM10/31/11
to android...@googlegroups.com
I haven't looked into your code yet, but what do expect the line "System.loadLibrary("opencv");" should load?
Do you really have a file libopencv.so somewhere? OpenCV for Android binary package doesn't contain it.

Francesco Lupia

unread,
Oct 31, 2011, 11:11:53 AM10/31/11
to android...@googlegroups.com
Hello Andrey,

Yeah I have libopencv.so which it is placed inside my project in libs/armeabi-v7a/ (of course it generated through the ndk-build command), but for some reason I can't load it.
Is there a way to do that matching which uses "SURF" through OpenCV for Android binary package? Since I couldn't find it, I'm trying to use the find_obj.cpp demo. Thank you for your reply.

Francesco Lupia

unread,
Nov 1, 2011, 7:17:34 AM11/1/11
to android...@googlegroups.com
Hello,

I managed to get rid of that exception, the problem was in the Application.mk which I didn't upload. Basically I changed this line: APP_ABI := armeabi-v7a to APP_ABI := armeabi and now I can load the libopencv.so without problems.

Anyway I'm not sure about my code.

As well as you can see in the find_obj.cpp demo, I have a vector named "vector<int> ptpairs;" which i use in the "flannFindPairs" that is my primary image match function.

At the end of this method I retrieve the ptpairs.size(), that, if I'm not wrong, it should be the matches, but I compared these matches with those from this app "http://it.appbrain.com/app/surf-image-matching/test.photo3dapps.surf" and I get a different result, for the same test images of course.

So I'm trying to understand what is wrong, any help is appreciated, thank you.

Andrey Kamaev

unread,
Nov 1, 2011, 11:48:55 AM11/1/11
to android-opencv
Hi,

FLANN uses some probabilistic method to find the matches. So resulting
matches can have a small variation between runs.

/Andrey

Francesco Lupia

unread,
Nov 1, 2011, 5:45:45 PM11/1/11
to android...@googlegroups.com
Hello,

First of all thank you for your reply. I'm still not sure about the "vector<int> ptpairs" size being what I'm looking for, i.e. the number of matches between 2 images. So I tried something different that is a counter inside this for:

int matches = 0;
    for (int i=0;i<m_indices.rows;++i) {
        if (dists_ptr[2*i]<0.6*dists_ptr[2*i+1]) {
            ptpairs.push_back(i);
            ptpairs.push_back(indices_ptr[2*i]);
        matches++;
        }
    }

in the flannFindPairs( const CvSeq*, const CvSeq* objectDescriptors, const CvSeq*, const CvSeq* imageDescriptors, vector<int>& ptpairs ) fuction.

Anyway I compiled the find_obj.cpp sample for linux too and I'm using the same sample images, i.e. box.png and box_in_scene.png.

I run the demo (on linux) several times and I get for every run the same result.

I did the same on android, same code, same images, and I get a different result which it is for every run always the same.

Now even if there is some probabilistic method, I can't see why I get two different results which don't change.

Of course I tried the same images with that app "Surf image matching" and I get another result which it is different from the other two, but since I don't have the source code I don't know what is going on there.

Any hints? What do you believe is the right way to get that number of matches? Thank you and sorry if I was a little bit long but I just tried to explain how things are.

Yau Mun

unread,
Jul 17, 2012, 12:01:26 AM7/17/12
to android...@googlegroups.com
Hi  Francesco Lupia  ,

I'm having a project on image recognition using Android platform. My project quite similar with yours. Can you describe briefly about how to start from scratch? This is due to im not expert on this field. Hope you can give some guidance to me. Thanks in advance. 

Reply all
Reply to author
Forward
0 new messages