unable to show matched descriptors in android

174 views
Skip to first unread message

Engr Muhammad Zeeshan Siddique

unread,
Apr 17, 2012, 2:28:02 PM4/17/12
to android...@googlegroups.com
i am creating an application for finding matches between two image. but i am not able to properly find match results. match methods me the same no of descriptors as the input images keypoints. 
 and i am also unable to draw this result as will. 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.FLANNBASED);
//  matcher.match(descriptors2, descriptors1, matches);
 matcher.match(descriptors2, 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);
//  Imgproc.cvtColor(rgb3, o_image3, Imgproc.COLOR_RGB2RGBA);  
 Utils.matToBitmap(o_image1, mBitmap1);
 mimageview1.setImageBitmap(mBitmap1);
 Utils.matToBitmap(temp, mBitmap2);
 mimageview2.setImageBitmap(mBitmap2);
//  Utils.matToBitmap(o_image3, mBitmap2);
//  Bitmap image = Bitmap.createScaledBitmap(mBitmap2, 1000, 1000, true);
//  mimageview3.setImageBitmap(image);
 s_image1.release();
 s_image2.release(); 
 o_image1.release();
 o_image2.release();

Rui Marques

unread,
Apr 19, 2012, 5:24:17 PM4/19/12
to android...@googlegroups.com
I would use 
matcher.match(descriptors2, descriptors1, matches);
that you commented.

Instead of
matcher.match(descriptors2, matches);

This is a way to display a match.
Iterating a list of matches with index i:
Core.circle(Mat, points.get( matches.get(i).trainIdx ).pt, 8, color, 1);

Engr Muhammad Zeeshan Siddique

unread,
Apr 20, 2012, 6:11:47 AM4/20/12
to android...@googlegroups.com
thanx for your help. but sir how can i filter required descriptors from the list(matches) when we use bruteforce matcher it's find a match of trainindx against every queryindex. it is my requirement because i have to calculate the result in terms of percentage.
--
Thanks & Best Regards,
Muhammad Zeeshan Siddique
Software Engineer
Zee Technologies


Rui Marques

unread,
Apr 20, 2012, 6:16:09 AM4/20/12
to android...@googlegroups.com
Each match object has a distance property, the smaller the distance the better the match.
(DMatch) match.distance

Engr Muhammad Zeeshan Siddique

unread,
Apr 20, 2012, 6:28:28 AM4/20/12
to android...@googlegroups.com
but sir if i change the location of descriptors in the match function then result will change like
matcher.match(descriptors2, descriptors1, matches); 
matcher.match(descriptors1, descriptors2, matches); 

how can i handle this situation...


On Fri, Apr 20, 2012 at 3:16 PM, Rui Marques <rui...@gmail.com> wrote:
Each match object has a distance property, the smaller the distance the better the match.
(DMatch) match.distance




Reply all
Reply to author
Forward
0 new messages