xfeatures2d/src/freak.cpp:337: error

asked 2017-07-02 17:58:58 -0600

open_ranger gravatar image

I am using android studio to implement feature detection in android apps.all other function STFT SURF ORB BRISK works but not FREAK. debug message:

java.lang.RuntimeException: An error occured while executing doInBackground()
  at android.os.AsyncTask$3.done(AsyncTask.java:300)
  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
  at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
  at java.util.concurrent.FutureTask.run(FutureTask.java:242)
  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
  at java.lang.Thread.run(Thread.java:841)
   Caused by: CvException [org.opencv.core.CvException: cv::Exception: ../../contrib/modules/xfeatures2d/src/freak.cpp:337: error: (-215) grayImage.channels() == 1 in function virtual void cv::xfeatures2d::FREAK_Impl::compute(cv::InputArray, std::vector<cv::KeyPoint>&, cv::OutputArray)
                                                                 ]
  at org.opencv.features2d.DescriptorExtractor.compute_0(Native Method)
  at org.opencv.features2d.DescriptorExtractor.compute(DescriptorExtractor.java:107)
  at wxh.objectdetection.MainActivity.executeTask(MainActivity.java:283)
  at wxh.objectdetection.MainActivity.access$100(MainActivity.java:53)
  at wxh.objectdetection.MainActivity$2.doInBackground(MainActivity.java:212)
  at wxh.objectdetection.MainActivity$2.doInBackground(MainActivity.java:201)
  at android.os.AsyncTask$2.call(AsyncTask.java:288)
  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                        ... 4 more

I went into app/src/jni/freak.cpp and changed line 337 from

// Convert to gray if not already
Mat grayImage = image;
CV_Assert(grayImage.channels() == 1);

to

// Convert to gray if not already
Mat grayImage = image;
//CV_Assert(grayImage.channels() == 1);
if (grayImage.channels()!=1){
    cvtColor(grayImage,grayImage,COLOR_RGBA2GRAY);
}

Still compile/run with same error, why?

edit retag flag offensive close merge delete

Comments

you'll have to rebuild the opencv libraries, if you change anyting there

berak gravatar imageberak ( 2017-07-02 21:13:52 -0600 )edit

I only know to recompile opencv-4-android-sdk,it takes about a hour or so.It's not a viable option if I just change a few line of code for testing purpose.How do we recompile the library inside android stuidio?

open_ranger gravatar imageopen_ranger ( 2017-07-03 04:40:18 -0600 )edit

tbh, i don't even understand, why you try to change the opencv library code.

the assertion in FREAK::compute() isa hint, that you need a single channel grayscale image as input. just supply that, instead of changing the code.

berak gravatar imageberak ( 2017-07-03 08:04:00 -0600 )edit