Ask Your Question
0

locate the object recognition Android OpenCV

asked 2013-03-18 08:06:23 -0500

Marwen Z gravatar image

updated 2013-03-18 10:20:41 -0500

Hi, with a reference image I just want to draw matches in the image of the video stream without use Features2d.drawMatches () because it not responding in my code

    Mat descriptors,descriptors1 = new Mat();
    keypoints = new MatOfKeyPoint();
    keypoints1 = new MatOfKeyPoint();
    detector = FeatureDetector.create(FeatureDetector.ORB);
    detector.detect(img1, keypoints);
    detector.detect(img2, keypoints1);
    descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    descriptor.compute(img1, keypoints, descriptors);
    descriptor.compute(img2, keypoints1, descriptors1);
   DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
    MatOfDMatch  matches = new MatOfDMatch();
    matcher.match(mIntermediateMat, descriptors, matches);
// draw matches just only in image img2 ....... locate the object recognition
edit retag flag offensive close merge delete

Comments

1

Maybe just to mention, that going another way, just because the code is not responding, isn't a very good way to program. It would be better to share your errors and ask us to help you solve it. Those functionalities are created with a reason, by people who actually understand the complete process. They can help you get more insight in the problem.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-21 07:07:19 -0500 )edit

@StevenPuttemans my problem is i drawFeatures for a good matching so i need to create a new MatOfDmatch to push good matching but i didn't find a good code for that because Feature2d.drawMatches() need to MatOfDmatch and not List<Dmatch> did you have a solution that create a MatOfDmatch from others MatOfDmatch

Marwen Z gravatar imageMarwen Z ( 2013-03-21 08:34:40 -0500 )edit

3 answers

Sort by ยป oldest newest most voted
0

answered 2013-03-21 09:03:52 -0500

Marwen Z gravatar image

i solve the problem it was simple :p but same thing that give me things that not exist in fisrt image

      List<DMatch> goodMatchesList = new ArrayList<DMatch>();

    DMatch dm12[]=matches12.toArray();
    DMatch dm21[]=matches21.toArray();
    for(int i=0;i<dm12.length;i++)
     {
     DMatch forward = dm12[i];  
        DMatch backward = dm21[forward.trainIdx];
        if( backward.trainIdx == forward.queryIdx ) 
            goodMatchesList.add(forward) ;

     }

    matches.fromList(goodMatchesList);
    matcher.match(descriptors,mIntermediateMat, matches);

    mIntermediateMat2.create(resultSize, CvType.CV_8UC1);


    Features2d.drawMatches( mGraySubmat, mKeyPoints, img1, keypoints,matches, mIntermediateMat2,GREEN, RED,  MATCH_MASK, Features2d.NOT_DRAW_SINGLE_POINTS);
edit flag offensive delete link more
0

answered 2013-03-21 06:38:32 -0500

Marwen Z gravatar image

updated 2013-03-21 06:39:04 -0500

@Mathieu Barnachon i procced like this

 MatOfDMatch matches, matches12, matches21;
    matcher.match( descriptors1, descriptors2, matches12 );
    matcher.match( descriptors2, descriptors1, matches21 );
 // iterate matches12
        DMatch forward = matches12[i];  // error convert from c++ to java
        DMatch backward = matches21[forward.trainIdx]; 
        if( backward.trainIdx == forward.queryIdx ) 
         matches.push_back( forward );  // error convert from c++ to java
    get the good matches  then draw it
     Features2d.drawMatches( mGraySubmat, mKeyPoints,img1, keypoints, matches, mIntermediateMat2,GREEN, RED,  MATCH_MASK, Features2d.NOT_DRAW_SINGLE_POINTS);
edit flag offensive delete link more
2

answered 2013-03-19 08:40:35 -0500

MatOfDMatch.toArray gives you the index of points for each image (train and query) to MatOfKeypoints if I'm right.

Transform your MatOfKeypoints to an array of Keypoints (with toArray), and iterate through the Point of keypoints (.pt), according to MatOfDMatch indices, and draw rectangle/circle or whatever you want with pt.x and pt.x coordinates.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-03-18 08:06:23 -0500

Seen: 1,499 times

Last updated: Mar 21 '13