0

I try to do like this theard Error matching with ORB in Android

But when i use matcher.match(descriptors1,descriptors2,matches); My app is exit and say "Unfortumatively, Car_Traking_1 has stopped"

This is my code when i not use matcher.match(descriptors1,descriptors2,matches); It's run and i can see data of descriptor1,descriptor1 in logcat

This is my code:

 public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    mImageRGBA = inputFrame.rgba();
    Utils.bitmapToMat(icon, img_object);
    Imgproc.cvtColor(mImageRGBA,img_scene,Imgproc.COLOR_RGBA2GRAY);


    FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
    DescriptorExtractor descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);;
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);

    //first image
    Mat img1 = img_object;
    Mat descriptors1 = new Mat();
    MatOfKeyPoint keypoints1 = new MatOfKeyPoint();

    detector.detect(img1, keypoints1);
    descriptor.compute(img1, keypoints1, descriptors1);

    //second image
    Mat img2 = img_scene;
    Mat descriptors2 = new Mat();
    MatOfKeyPoint keypoints2 = new MatOfKeyPoint();

    detector.detect(img2, keypoints2);
    descriptor.compute(img2, keypoints2, descriptors2);

    //matcher should include 2 different image's descriptors
    Log.i("aaa1", descriptors1.dump());
    Log.i("aaa2",descriptors2.dump());
    Log.i("aaa3",String.valueOf(descriptors1.cols()));
    Log.i("aaa4",String.valueOf(descriptors1.rows()));
    Log.i("aaa5",String.valueOf(descriptors2.cols()));
    Log.i("aaa6",String.valueOf(descriptors2.rows()));



    return mImageRGBA;
}

I see descriptor1 and descriptor2 have data, size of descriptor1 is 32x104 and size of descriptor1 is 32x219

But now when i add 2 line

        MatOfDMatch matches = new MatOfDMatch();
    matcher.match(descriptors1,descriptors2,matches);

So my code will like

 public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    mImageRGBA = inputFrame.rgba();
    Utils.bitmapToMat(icon, img_object);
    Imgproc.cvtColor(mImageRGBA,img_scene,Imgproc.COLOR_RGBA2GRAY);


    FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
    DescriptorExtractor descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);;
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);

    //first image
    Mat img1 = img_object;
    Mat descriptors1 = new Mat();
    MatOfKeyPoint keypoints1 = new MatOfKeyPoint();

    detector.detect(img1, keypoints1);
    descriptor.compute(img1, keypoints1, descriptors1);

    //second image
    Mat img2 = img_scene;
    Mat descriptors2 = new Mat();
    MatOfKeyPoint keypoints2 = new MatOfKeyPoint();

    detector.detect(img2, keypoints2);
    descriptor.compute(img2, keypoints2, descriptors2);

    //matcher should include 2 different image's descriptors
    MatOfDMatch matches = new MatOfDMatch();
    matcher.match(descriptors1, descriptors2, matches);



    return mImageRGBA;
}

When i run it, it run and exit and say "Unfortumatively, Car_Traking_1 has stopped" I don't know what problem with it, or descriptor1 and descriptor2 had to same size. How can i fix it.

Community
  • 1
  • 1
Bruce
  • 519
  • 6
  • 23

1 Answers1

0

Did you convert your OBJECT image to gray? You converted scene photo with this code on the start of onCameraFrame:

mImageRGBA = inputFrame.rgba(); Utils.bitmapToMat(icon, img_object); Imgproc.cvtColor(mImageRGBA,img_scene,Imgproc.COLOR_RGBA2GRAY);

but where did you converted object image to the same format?

Before calculating descriptor and keypoints of object image you should convert it to gray:

Imgproc.cvtColor(OBJECT_IMAGE,img_object,Imgproc.COLOR_RGBA2GRAY);

Just be careful to convert object image to Mat() before using this above. If its bitmap you can convert it on the same way as you did with scene image.

tompadre
  • 797
  • 7
  • 22