Error matching with ORB in Android

asked 2013-03-21 03:14:00 -0500

Marwen Z gravatar image

updated 2013-03-21 04:40:29 -0500

my code here working good but when he extract keypoints he makes a poor match between the two images ie it does not give good matching

             descriptors = new Mat();
    keypoints = new MatOfKeyPoint();
    detector = FeatureDetector.create(FeatureDetector.ORB);
    detector.detect(img1, keypoints);
    descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    descriptor.compute(img1, keypoints, descriptors);
    matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
 ColorDetection.cvt_YUVtoRGBtoHSV(mYuv,mGraySubmat);
      MatOfKeyPoint mKeyPoints = new MatOfKeyPoint();
    MatOfDMatch  matches = new MatOfDMatch();

      detector.detect(mGraySubmat, mKeyPoints);
      descriptor.compute(mGraySubmat, mKeyPoints, mIntermediateMat);

    matcher.match(mIntermediateMat,descriptors,matches);
    mIntermediateMat2.create(resultSize, CvType.CV_8UC1);
    Features2d.drawMatches(img1, keypoints, mGraySubmat, mKeyPoints, matches, 
            mIntermediateMat2,GREEN, RED,  MATCH_MASK, Features2d.NOT_DRAW_SINGLE_POINTS);

      Imgproc.resize(mIntermediateMat2, mIntermediateMat2, mRgba.size());
      Imgproc.cvtColor(mIntermediateMat2, mRgba, Imgproc.COLOR_RGBA2BGRA, 4);
 Utils.matToBitmap(mRgba, bmp);

// i added this following code

  DMatch dm[] = matches.toArray();
      List<Point> lp1 = new ArrayList<Point>(dm.length);
      List<Point> lp2 = new ArrayList<Point>(dm.length);
      KeyPoint tkp[] = keypoints.toArray();
      KeyPoint qkp[] = mKeyPoints.toArray();
      for (int i = 0; i < dm.length; i++) {
          DMatch dma = dm[i];
          lp1.add(tkp[dma.trainIdx].pt);
          lp2.add(qkp[dma.queryIdx].pt);
      }
      MatOfPoint2f pointsPrev = new MatOfPoint2f(lp1.toArray(new Point[0]));
      MatOfPoint2f pointsAct  = new MatOfPoint2f(lp2.toArray(new Point[0]));
    Log.i("pointsPrev", pointsPrev.size().toString());
    Log.i("pointsAct", pointsAct.size().toString());
      fundamental_matrix.create(resultSize, CvType.CV_8UC1);
    fundamental_matrix = Calib3d.findFundamentalMat(
              pointsAct, pointsPrev, Calib3d.FM_RANSAC, 3, 0.99);
edit retag flag offensive close merge delete