Drawing match pairs in the image calculated by KNN and potential error in Feature2DToolbox.DrawMatches

I wrote a code that finds the closest matches to K using the KNN algorithm. Having received matMatch and matchIndices, I tried to draw pairs of matches between two frames of consequences.

I pass matMask and matchIndices to the Features2DToolbox.DrawMatches function:

Image<Bgr, byte> imResult = Features2DToolbox.DrawMatches(imModelCurr, imModel.keyPoints, imObserPrev,imObser.keyPoints, **matchIndices**, new Bgr(System.Drawing.Color.Yellow), new Bgr(System.Drawing.Color.Red), **matMask**, Features2DToolbox.KeypointDrawType.NOT_DRAW_SINGLE_POINTS); 

http://www.emgu.com/wiki/files/2.4.0/document/html/e92d37e6-fe4a-ad09-9304-cd2d2533bfa8.htm , but I noticed that it returns an invalid pattern between matching pairs:

enter image description here

Then I tried to implement such a function myself:

  for (int i = 0; i < matMask.Rows; ++i) { if (**matMask[i, 0]** > 0) { int indForCurrFrm = **matchIndices[i, 0]**; int indForPrevFrm = i; //for frame i-1 PointF fromFirstFrame = getImgObserved(keyPoints[indForPrevFrm]); //for frame i PointF NextCorrespondingMatchedFrame = getImModelXY(keyPoints[indForCurrFrm]); imColorPrv2.Draw(new CircleF(fromFirstFrame, 5), new Bgr(mtchColor), 3);// for frame i-1 imColorShow.Draw(new CircleF(NextCorrespondingMatchedFrame, 5), new Bgr(mtchColor), 3); // for frame i // draw line on my own matching imResult.Draw(new LineSegment2DF(fromFirstFrame,NextCorrespondingMatchedFrame),new Bgr(System.Drawing.Color.FloralWhite),1); } } 

and select the corresponding coordinates of the pairs of points (X, Y) and draw them yourself (see the results in the picture).

In the lower left corner you can see the coincidences (shown by a white line) and each corresponding pair with a circle of the same color [according to my own function], and on the other hand - at the bottom right, these are the results drawn by the DrawMatches function from Emgu.Pay note that these two functions use the same matMash and matchIndices.

So, I was wondering if there are DrawMatches in EMGU with errors or am I doing something wrong?

+7
source share
1 answer

It can be very useful to filter the best matches from matchIndices using the Euclidean distance between the descriptors of each matching pair. Sometimes several key points from the first image can correspond to many key points from the second image, this can confuse the constructed lines in the results.

Filtering might be something like this:

 vector< DMatch > filtered_matches; for( int i = 0; i < descriptors_of_model.rows; i++ ) { if( matchIndices[i].distance < SMALL_THRESHOLD ) filtered_matches.push_back( matchIndices[i]); } 
0
source

All Articles