c# - Drawing match pairs in image-calculated by KNN and the potential bug in Features2DToolbox.DrawMatches -
i wrote code finds k closest matches knn algorithm. after getting matmatch , matchindices tried draw match pairs between 2 consequence frames.
i feed matmask , matchindices function features2dtoolbox.drawmatches :
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 noticed gives me wrong drawing between matching pairs:
then tried implement such function myself:
(int = 0; < 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 pointf nextcorrespondingmatchedframe = getimmodelxy(keypoints[indforcurrfrm]); imcolorprv2.draw(new circlef(fromfirstframe, 5), new bgr(mtchcolor), 3);// frame i-1 imcolorshow.draw(new circlef(nextcorrespondingmatchedframe, 5), new bgr(mtchcolor), 3); // frame // draw line on own matching imresult.draw(new linesegment2df(fromfirstframe,nextcorrespondingmatchedframe),new bgr(system.drawing.color.floralwhite),1); } }
and fetch corresponding pair point coordinates (x,y) , draw myself [ see results in snapshot].
one left bottom see matches(shown white line) , each corresponding pairs circle in same color [by own function] , on other side-bottom right , results drawn drawmatches function emgu.pay attention these 2 functions use same matmash , matchindices.
so wondering if drawmatches @ emgu has bugs or doing somewhere wrong?
it might useful filter best matches matchindices, using euclidean distance between descriptors of each corresponding pair . times 1 keypoints first image can match many keypoints second image, can confuse plotted lines in results.
filtering like:
vector< dmatch > filtered_matches; for( int = 0; < descriptors_of_model.rows; i++ ) { if( matchindices[i].distance < small_threshold ) filtered_matches.push_back( matchindices[i]); }
Comments
Post a Comment