SURF and SIFT algorithms doesn't work in OpenCV 3.0 Java for android

asked 2016-11-30 08:11:49 -0500

nadia gravatar image

updated 2016-11-30 09:26:43 -0500

I tried to use Sift or surf descriptors for machine learning in an android application. But when i run the program i get this error.

OpenCV Error: Bad argument (Specified feature detector type is not supported.) in cv::javaFeatureDetector::create

My code:

public   void train() {

 // Creating Training Data
   Mat trainData = new Mat();
  Mat train_labels = new Mat();

     Mat descriptors ;
    FeatureDetector featureDetector;
     MatOfKeyPoint keyPoints;
     DescriptorExtractor descriptorExtractor;
Mat descriptors1 ;
FeatureDetector featureDetector1;
MatOfKeyPoint keyPoints1;
DescriptorExtractor descriptorExtractor1;


    String Newligne=System.getProperty("line.separator");


  for (int i = 0; i <48; i++) {

   String path1 = Environment.getExternalStorageDirectory().toString()
   + "/Pictures/images/" + "a"+i + ".jpg";
     /* String path1 = Environment.getExternalStorageDirectory().toString()
        + "/Pictures/images/" +"a"+ i + ".jpg";*/

     Mat img = Imgcodecs.imread(path1);
featureDetector=FeatureDetector.create(FeatureDetector.PYRAMID_FAST);
descriptorExtractor=DescriptorExtractor.create(DescriptorExtractor.SIFT);
keyPoints = new MatOfKeyPoint();
descriptors = new Mat();
featureDetector.detect(img, keyPoints);
Log.d("LOG!", "number of query Keypoints= " + keyPoints.size());
// Descript keypoints
descriptorExtractor.compute(img, keyPoints, descriptors);
Log.d("LOG!", "number of descriptors= " + descriptors.size());

     Log.i(TAG,"error"+i+img.empty());


         trainData.push_back(descriptors)// add 1 item
        train_labels.push_back(new Mat(1, 1, CvType.CV_32SC1, new Scalar(i)));

         }
edit retag flag offensive close merge delete

Comments

can you show us some code for more details?

Vintez gravatar imageVintez ( 2016-11-30 09:06:25 -0500 )edit

i put my code. Can you help me

nadia gravatar imagenadia ( 2016-11-30 09:27:58 -0500 )edit

sad as it is, sift & surf were moved to opencv_contrib, and the java bindings did not survive that move.

berak gravatar imageberak ( 2016-11-30 09:45:25 -0500 )edit
1

Well, then a Possibility to use them in Android would be when you use OpenCV as native Library. Here A answer which explains how to build opencv for Android. As Berak mentioned, SIFT and SURF have been moved to opencv-contrib so you have to build opencv with that included.

Vintez gravatar imageVintez ( 2016-11-30 09:48:29 -0500 )edit

Concerning BOW is it supported by java ?

nadia gravatar imagenadia ( 2016-11-30 09:53:49 -0500 )edit

@nadia, from plain java atm, - not at all

(go , and run wild with the natives ...)

berak gravatar imageberak ( 2016-11-30 10:01:04 -0500 )edit

I am sorry for the disturbance but i have an other question. which types of texture or shape descriptors opencv can use

nadia gravatar imagenadia ( 2016-11-30 12:15:04 -0500 )edit

Hello. I am newbie and I write on Windows 10 PC, so Android and Linux ways to solve the same problem as in topic are not applicable. Can someone help me?

PavloSehiienko gravatar imagePavloSehiienko ( 2017-11-25 14:33:38 -0500 )edit

i have this problem How did you solve it Please?

My email: eng.mazen96@gmail.com

Mazen Mohamed gravatar imageMazen Mohamed ( 2018-04-25 15:06:33 -0500 )edit