larael / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

How to use ObjectFinder, Stitcher, etc. with SURF on Android #214

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

I have problems running ObjectFinder on Android. 

this is my code:

{

double[] dstCorners;

ObjectFinder objFinder = new ObjectFinder(object);

dstCorners = objFinder.find(image_1);

}

it produece the error:

" java.lang.RuntimeException: java.lang.RuntimeException: 
/home/saudet/android/OpenCV-2.4.0/modules/legacy/src/features2d.cpp:77: error: 
(-213) OpenCV was built without SURF support in function void 
cvExtractSURF(const CvArr*, const CvArr*, CvSeq**, CvSeq**, CvMemStorage*, 
CvSURFParams, int)"

What version of the product are you using? On what operating system?
Eclipse (Android 3.0 or newer): 

Please provide any additional information below.

Original issue reported on code.google.com by t910...@gmail.com on 6 Jul 2012 at 3:25

GoogleCodeExporter commented 9 years ago
What files do you have in the `libs/armeabi` subdirectory?

Original comment by samuel.a...@gmail.com on 7 Jul 2012 at 3:09

GoogleCodeExporter commented 9 years ago

libs>>

javacv.jar
javacpp.jar
armeabi>>

libjniARToolKitPlus.so      libjniopencv_legacy.so     libopencv_features2d.so
libjniavcodec.so            libjniopencv_ml.so         libopencv_flann.so
libjniavdevice.so           libjniopencv_nonfree.so    libopencv_highgui.so
libjniavformat.so           libjniopencv_objdetect.so  libopencv_imgproc.so
libjniavutil.so             libjniopencv_photo.so      libopencv_legacy.so
libjnicvkernels.so          libjniopencv_stitching.so  libopencv_ml.so
libjniopencv_calib3d.so     libjniopencv_video.so      libopencv_nonfree.so
libjniopencv_contrib.so     libjniopencv_videostab.so  libopencv_objdetect.so
libjniopencv_core.so        libjnipostproc.so          libopencv_photo.so
libjniopencv_features2d.so  libjniswscale.so           libopencv_stitching.so
libjniopencv_flann.so       libopencv_calib3d.so       libopencv_video.so
libjniopencv_highgui.so     libopencv_contrib.so       libopencv_videostab.so
libjniopencv_imgproc.so     libopencv_core.so

the *.so files from javacv-android-arm.jar, 
the *.so files form OpenCV-2.4.0-android-arm.zip
it contain armeabi and armeabi-v7a folder

Original comment by t910...@gmail.com on 9 Jul 2012 at 3:09

GoogleCodeExporter commented 9 years ago
I'll have to check later, but maybe one of the modules are not loading 
properly.. Does it change anything if you add 
`Loader.load(opencv_nonfree.class)` before using ObjectFinder?

Original comment by samuel.a...@gmail.com on 9 Jul 2012 at 3:11

GoogleCodeExporter commented 9 years ago
I want to add 'Loader.load(opencv_nonfree.class)` 

but it show that the method "load" is undefined

so I try to rewrite my code as:

vodi func()
{

         int w1,h1;
         int w2,h2;

         String root = Environment.getExternalStorageDirectory().toString();
         Log.d("my tag ","root=" + root);

         Bitmap bmp1 = BitmapFactory.decodeFile(root+"/kkc/3.jpg"); 
         Bitmap bmp2 = BitmapFactory.decodeFile(root+"/kkc/2.jpg"); 

         if(bmp1  == null)
         {
                Log.d("my tag", "It's null");

         }
         if(bmp2  == null)
         {
                Log.d("my tag", "It's null");

         }

         w1 = bmp1.getWidth();
             h1 = bmp1.getHeight();  
         w2 = bmp2.getWidth();
             h2 = bmp2.getHeight();  

         Log.d("my tag ","Load Image");

         IplImage object = IplImage.create(w1, h1, IPL_DEPTH_8U, 4);
         IplImage object_1 = IplImage.create(w1, h1, IPL_DEPTH_8U, 1);

         bmp1.copyPixelsToBuffer(object.getByteBuffer());
         cvCvtColor(object, object_1, CV_BGR2GRAY);
         Log.d("my tag ","cvCvtColor");

         IplImage image = IplImage.create(w2, h2, IPL_DEPTH_8U, 4);
         IplImage image_1 = IplImage.create(w2, h2, IPL_DEPTH_8U, 1);

         bmp2.copyPixelsToBuffer(image.getByteBuffer());
         cvCvtColor(image, image_1, CV_BGRA2GRAY);
         Log.d("my tag ","cvCvtColor");

         Log.d("my tag ","Load Image");

     load(opencv_features2d.class); 
         double[] dstCorners;
         ObjectFinder objFinder = new ObjectFinder(object);

         dstCorners = objFinder.find(image_1);

}

Finally, I get same error >"<

Original comment by t910...@gmail.com on 11 Jul 2012 at 2:45

GoogleCodeExporter commented 9 years ago
And what if you replace `load(opencv_features2d.class)` by 
`load(opencv_nonfree.class)` ?

Original comment by samuel.a...@gmail.com on 11 Jul 2012 at 2:47

GoogleCodeExporter commented 9 years ago
I have just released JavaCV 0.2. Do you still have problems with that release? 
Or has this issue been fixed?

Original comment by samuel.a...@gmail.com on 22 Jul 2012 at 12:44

GoogleCodeExporter commented 9 years ago
thanks for your help 

but,there are stll errors

it show 

"java.lang.NoClassDefFoundError: com.googlecode.javacv.ObjectFinder$Settings"

I found out one of Issues abput "objectfiner"

You gave someone an instructions

*BEFORE* following the instructions in the README.txt file: 
1. Remove BaseChildSettings.class and BaseSettings.class from 
javacv.jar 
2. Follow the instructions in the README.txt file 
3. In your project, define empty classes BaseChildSettings and 
BaseSettings under the com.googlecode.javacv package name 

SO I have to obey these instruction? 

Original comment by t910...@gmail.com on 23 Jul 2012 at 6:59

GoogleCodeExporter commented 9 years ago
Yes, we still need to use that hack :(

Original comment by samuel.a...@gmail.com on 23 Jul 2012 at 10:05

GoogleCodeExporter commented 9 years ago
I use that hack , 

It show as:

java.lang.RuntimeException: 
Unable to start activity 
ComponentInfo{com.demo.android.TRYOBJ1/com.demo.android.TRYOBJ1.TRYOBJActivity}:

java.lang.RuntimeException: 
/home/saudet/android/OpenCV-2.4.2/modules/legacy/src/features2d.cpp:77: error: 
(-213) 
OpenCV was built without SURF support in function void cvExtractSURF(const 
CvArr*, const CvArr*, CvSeq**, CvSeq**, CvMemStorage*, CvSURFParams, int)

The library could be placed on the false postion?

Original comment by t910...@gmail.com on 24 Jul 2012 at 3:59

GoogleCodeExporter commented 9 years ago
Like I said, what happens if you call `load(opencv_nonfree.class)`?

Original comment by samuel.a...@gmail.com on 24 Jul 2012 at 4:21

GoogleCodeExporter commented 9 years ago
This is my compelete code:

package com.demo.android.TRYOBJ1;

import android.app.Activity;
import android.os.Bundle;

import java.io.File;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Loader;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Environment;
import android.text.format.Time;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.nio.FloatBuffer; 
import java.nio.IntBuffer; 
import java.util.ArrayList; 
import java.util.logging.Logger; 

import com.googlecode.javacv.BaseChildSettings;

import com.googlecode.javacv.ObjectFinder;
//import com.googlecode.javacv.ObjectFinder$Settings;

import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_features2d;
import com.googlecode.javacv.cpp.opencv_nonfree;

import static com.googlecode.javacpp.Loader.*;  
import static com.googlecode.javacv.cpp.opencv_calib3d.*; 
import static com.googlecode.javacv.cpp.opencv_core.*; 
import static com.googlecode.javacv.cpp.opencv_flann.*; 
import static com.googlecode.javacv.cpp.opencv_highgui.*; 
import static com.googlecode.javacv.cpp.opencv_imgproc.*; 
import static com.googlecode.javacv.cpp.opencv_legacy.*; 
import static com.googlecode.javacv.cpp.opencv_objdetect.*;

public class TRYOBJActivity extends Activity {
    /** Called when the activity is first created. */

    private ImageView imageview01;
    private Button button_primary;
    private Button button_gray;
    private Button button_canny;
    private TextView flag;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);

        Log.d("my tag", "setview");

        //imageview01 = (ImageView)this.findViewById(R.id.imageView1); 

        func();

    }
    private void func() { 

         load(opencv_nonfree.class);
         int w1,h1;
         int w2,h2;

         String root = Environment.getExternalStorageDirectory().toString();
         Log.d("my tag ","root=" + root);

         Bitmap bmp1 = BitmapFactory.decodeFile(root+"/kkc/3.jpg"); 
         Bitmap bmp2 = BitmapFactory.decodeFile(root+"/kkc/2.jpg"); 

         if(bmp1  == null)
         {
                Log.d("my tag", "It's null");

         }
         if(bmp2  == null)
         {
                Log.d("my tag", "It's null");

         }

         w1 = bmp1.getWidth();
         h1 = bmp1.getHeight();  
         w2 = bmp2.getWidth();
         h2 = bmp2.getHeight();  

         Log.d("my tag ","Load Image");

         IplImage object = IplImage.create(w1, h1, IPL_DEPTH_8U, 4);
         IplImage object_1 = IplImage.create(w1, h1, IPL_DEPTH_8U, 1);

         bmp1.copyPixelsToBuffer(object.getByteBuffer());
         cvCvtColor(object, object_1, CV_BGR2GRAY);
         Log.d("my tag ","cvCvtColor");

         IplImage image = IplImage.create(w2, h2, IPL_DEPTH_8U, 4);
         IplImage image_1 = IplImage.create(w2, h2, IPL_DEPTH_8U, 1);

         bmp2.copyPixelsToBuffer(image.getByteBuffer());
         cvCvtColor(image, image_1, CV_BGRA2GRAY);
         Log.d("my tag ","cvCvtColor");

         cvSaveImage(root + "/kkc/gg.jpg",image);

         //for(int i=0;i<h2;i++)
         //{
         //Log.d("my tag ",cvGet2D(image_1,i,5).getVal(0) + " ");
         //}

         Log.d("my tag ","Load Image");

         //double[] dstCorners = new double [8];
         double[] dstCorners;
         ObjectFinder objFinder = new ObjectFinder(object_1);

         //dstCorners = objFinder.find(image_1);

        Log.d("my tag", "ObjectFinder");

    }

}

It reduces the error

07-24 13:10:39.253: E/AndroidRuntime(7546): FATAL EXCEPTION: main
07-24 13:10:39.253: E/AndroidRuntime(7546): java.lang.RuntimeException: Unable 
to start activity 
ComponentInfo{com.demo.android.TRYOBJ1/com.demo.android.TRYOBJ1.TRYOBJActivity}:
 java.lang.RuntimeException: 
/home/saudet/android/OpenCV-2.4.2/modules/legacy/src/features2d.cpp:77: error: 
(-213) OpenCV was built without SURF support in function void 
cvExtractSURF(const CvArr*, const CvArr*, CvSeq**, CvSeq**, CvMemStorage*, 
CvSURFParams, int)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
android.app.ActivityThread.access$600(ActivityThread.java:123)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
android.os.Handler.dispatchMessage(Handler.java:99)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
android.os.Looper.loop(Looper.java:137)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
android.app.ActivityThread.main(ActivityThread.java:4424)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
java.lang.reflect.Method.invokeNative(Native Method)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
java.lang.reflect.Method.invoke(Method.java:511)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
dalvik.system.NativeStart.main(Native Method)
07-24 13:10:39.253: E/AndroidRuntime(7546): Caused by: 
java.lang.RuntimeException: 
/home/saudet/android/OpenCV-2.4.2/modules/legacy/src/features2d.cpp:77: error: 
(-213) OpenCV was built without SURF support in function void 
cvExtractSURF(const CvArr*, const CvArr*, CvSeq**, CvSeq**, CvMemStorage*, 
CvSURFParams, int)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
com.googlecode.javacv.cpp.opencv_legacy.cvExtractSURF(Native Method)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
com.googlecode.javacv.ObjectFinder.setSettings(ObjectFinder.java:145)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
com.googlecode.javacv.ObjectFinder.<init>(ObjectFinder.java:51)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
com.demo.android.TRYOBJ1.TRYOBJActivity.func(TRYOBJActivity.java:149)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
com.demo.android.TRYOBJ1.TRYOBJActivity.onCreate(TRYOBJActivity.java:80)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
android.app.Activity.performCreate(Activity.java:4465)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
07-24 13:10:39.253: E/AndroidRuntime(7546):     at 
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
07-24 13:10:39.253: E/AndroidRuntime(7546):     ... 11 more

Original comment by t910...@gmail.com on 24 Jul 2012 at 5:19

GoogleCodeExporter commented 9 years ago
Does it still do that with JavaCV 0.2?

Original comment by samuel.a...@gmail.com on 2 Aug 2012 at 1:51

GoogleCodeExporter commented 9 years ago
This happens to me too, with JavaCV 2.0
will appreciate your prompt reply.

java.lang.RuntimeException: 
/home/saudet/android/OpenCV-2.4.2/modules/legacy/src/features2d.cpp:77: error: 
(-213) OpenCV was built without SURF support in function void 
cvExtractSURF(const CvArr*, const CvArr*, CvSeq**, CvSeq**, CvMemStorage*, 
CvSURFParams, int)

Original comment by Omry.Zobel on 31 Aug 2012 at 5:05

GoogleCodeExporter commented 9 years ago
Any luck with this yet? I'm getting the same error and 
'load(opencv_nonfree.class)' doesn't seem to help. I'm having the very same 
stack trace when trying to execute cvExtractSURF(). Please comment if any 
update.

Original comment by Dimitrow...@gmail.com on 17 Sep 2012 at 1:57

GoogleCodeExporter commented 9 years ago
I abandon the using of cvEXtractSURF with javacv

The success is made by compling new SO file with NDK 

Original comment by t910...@gmail.com on 19 Sep 2012 at 10:51

GoogleCodeExporter commented 9 years ago
This appears to be a bug in Android. I haven't found a way to work around it 
yet, but if anyone figures out a solution, please let me know! thank you

Original comment by samuel.a...@gmail.com on 24 Sep 2012 at 12:09

GoogleCodeExporter commented 9 years ago
Issue 249 has been merged into this issue.

Original comment by samuel.a...@gmail.com on 12 Oct 2012 at 9:17

GoogleCodeExporter commented 9 years ago
Hi, guys, if you still have this problem please check the following link:
https://groups.google.com/forum/#!topic/javacv/uuBToveMmOQ

I searched the Internet and I have solved this problem, If you want to use 
objectfinder in Android using Javacv please do as follows:
1、do what samuel said as follows:
BEFORE* following the instructions in the README.txt file:
>         1. Remove BaseChildSettings.class and BaseSettings.class from
>         javacv.jar
>         2. Follow the instructions in the README.txt file
>         3. In your project, define empty classes BaseChildSettings and
>         BaseSettings under the com.googlecode.javacv package name
2、import the following package in your project:
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.cpp.opencv_features2d;
import com.googlecode.javacv.cpp.opencv_nonfree;
3、use Loader.load(opencv_nonfree.class); in your code before you do the 
following

         MyObjectFinder objFinder = null; 
         MyObjectFinder.Settings objectFinderSettings = null; 

         try { 
                objectFinderSettings = new MyObjectFinder.Settings();
                objectFinderSettings.setObjectImage(object); 
                objFinder = new MyObjectFinder(objectFinderSettings); 

} catch (Exception e) { 
                      e.printStackTrace(); 
 } 

and then you can use objFinder.find(img) to compare 2 images.

I tried 2 days and finally solved it. feeling good!

Weitao

Original comment by xuweitao...@gmail.com on 19 Mar 2014 at 4:43

GoogleCodeExporter commented 9 years ago
@xuweitao005 Thanks for reporting! We now have a workaround, great :)

Can anyone confirm that it fixes issues with the Sticher and other things using 
SURF as well?

Original comment by samuel.a...@gmail.com on 20 Mar 2014 at 12:33

GoogleCodeExporter commented 9 years ago
Committed fix here:
http://code.google.com/p/javacv/source/detail?r=9f9f82497b661170d29d43784f04fdcb
3ad1f9c3
Thanks for reporting!

Original comment by samuel.a...@gmail.com on 31 Mar 2014 at 1:03

GoogleCodeExporter commented 9 years ago
The fix has been included in the latest release of JavaCV 0.8. Thanks for your 
cooperation! The stitching module should also be working as well now.

A lot of things have changed with this release, so please make sure to read 
this announcement here:
    http://bytedeco.org/release/2014/04/28/first-release.html

Original comment by samuel.a...@gmail.com on 29 Apr 2014 at 12:18