user1296460
user1296460

Reputation: 171

unable to implement descriptors in android

I am creating an application for finding matches between two images. I am not able to properly find match results.

Matching methods give me the same number of descriptors as the input keypoints and I am also unable to draw this result. I am using OpenCV as a library in the workspace.

Here is my code.

  Bitmap mBitmap1 = mimage1.copy(Bitmap.Config.ARGB_8888, false); 
  Bitmap mBitmap2 = mimage2.copy(Bitmap.Config.ARGB_8888, false); 

  Mat s_image1 = Utils.bitmapToMat(mBitmap1);
  Mat s_image2 = Utils.bitmapToMat(mBitmap2);

  Mat rgb1 = new Mat();
  Mat rgb2 = new Mat();
  Mat rgb3 = new Mat();
  Mat temp = new Mat();

  Mat o_image1 = new Mat();
  Mat o_image2 = new Mat();
  Mat o_image3 = new Mat();

  List<KeyPoint> points1 = new ArrayList<KeyPoint>();
  List<KeyPoint> points2 = new ArrayList<KeyPoint>();
  List<DMatch> matches = new ArrayList<DMatch>();

  FeatureDetector surf = FeatureDetector.create(FeatureDetector.SURF);
  surf.detect(s_image1, points1);
  surf.detect(s_image2, points2);

  Scalar color1 = new Scalar(0,255,0);
  Scalar color2 = new Scalar(255,0,0);

  Imgproc.cvtColor(s_image1, rgb1, Imgproc.COLOR_RGBA2RGB);
  Imgproc.cvtColor(s_image2, rgb2, Imgproc.COLOR_RGBA2RGB);

  Mat descriptors1 = new Mat(), descriptors2 = new Mat();
  Features2d.drawKeypoints(rgb1, points1, rgb1, color2);
  Features2d.drawKeypoints(rgb2, points2, rgb2, color2);
  DescriptorExtractor extracter = DescriptorExtractor.create(DescriptorExtractor.SURF);

  extracter.compute(rgb1, points1, descriptors1);
  extracter.compute(rgb2, points2, descriptors2);
  int k = 5;
  DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
  matcher.match(descriptors2, descriptors1, matches);
  Features2d.drawMatches(rgb1, points1, rgb2, points2, matches, rgb3, color1, color2);
  Imgproc.cvtColor(rgb1, o_image1, Imgproc.COLOR_RGB2RGBA);
  Imgproc.cvtColor(rgb2, o_image2, Imgproc.COLOR_RGB2RGBA);

  Utils.matToBitmap(o_image1, mBitmap1);
  mimageview1.setImageBitmap(mBitmap1);
  Utils.matToBitmap(o_image2, mBitmap2);
  mimageview2.setImageBitmap(mBitmap2);
  Utils.matToBitmap(o_image3, mBitmap3);
  mimageview3.setImageBitmap(mBitmap3);
  s_image1.release();
  s_image2.release(); 
  o_image1.release();
  o_image2.release();

Upvotes: 17

Views: 1654

Answers (1)

Y.AL
Y.AL

Reputation: 1793

In case of locked solution, I suggest you to use Android NDK and C++ native codes. it works properly. This tutorial is well explaining the step to do a jni-opencv project for android

Upvotes: 0

Related Questions