SURF Characteristic method

Source: Internet
Author: User

  Public Static voidFindmatch (Mat Modelimage, Mat Observedimage, out LongMatchtime, outVectorofkeypoint Modelkeypoints, outVectorofkeypoint observedkeypoints, Vectorofvectorofdmatch matches, outMat Mask, outMat homography) {            intK =2; DoubleUniquenessthreshold =0.8; DoubleHessianthresh = -;            Stopwatch Watch; Homography=NULL; Modelkeypoints=NewVectorofkeypoint (); Observedkeypoints=NewVectorofkeypoint (); using(Umat umodelimage =Modelimage.toumat (accesstype.read))using(Umat uobservedimage =Observedimage.toumat (Accesstype.read)) {SURF surfcpu=NewSURF (Hessianthresh); //extract features from the object imageUmat modeldescriptors =NewUmat (); Surfcpu.detectandcompute (Umodelimage,NULL, Modelkeypoints, Modeldescriptors,false); Watch=stopwatch.startnew (); //extract features from the observed imageUmat observeddescriptors =NewUmat (); Surfcpu.detectandcompute (Uobservedimage,NULL, Observedkeypoints, Observeddescriptors,false); Bfmatcher Matcher=NewBfmatcher (DISTANCETYPE.L2); Matcher.                ADD (modeldescriptors); Matcher. Knnmatch (observeddescriptors, matches, K,NULL); Mask=NewMat (matches. Size,1, depthtype.cv8u,1); Mask. Setto (NewMcvscalar (255));                Features2dtoolbox.voteforuniqueness (matches, uniquenessthreshold, mask); intNonzerocount =Cvinvoke.countnonzero (mask); if(Nonzerocount >=4) {Nonzerocount=features2dtoolbox.voteforsizeandorientation (modelkeypoints, observedkeypoints, matches, mask, /c4>1.5, -); if(Nonzerocount >=4) homography=features2dtoolbox.gethomographymatrixfrommatchedfeatures (modelkeypoints, Observedkeypoints, Matches, mask,2); } watch.            Stop (); } matchtime=Watch.        Elapsedmilliseconds; }        /// <summary>        ///Draw the model image and observed image, the matched features and homography projection. /// </summary>        /// <param name= "Modelimage" >The model image</param>        /// <param name= "Observedimage" >The observed image</param>        /// <param name= "Matchtime" >The output total time for computing the homography matrix.</param>        /// <returns>the model image and observed image, the matched features and homography projection.</returns>         Public StaticMat Draw (Mat Modelimage, Mat Observedimage, out Longmatchtime)            {Mat homography;            Vectorofkeypoint modelkeypoints;            Vectorofkeypoint observedkeypoints; using(Vectorofvectorofdmatch matches =NewVectorofvectorofdmatch ())                {Mat mask; Findmatch (Modelimage, Observedimage, outMatchtime, outModelkeypoints, outobservedkeypoints, Matches, outMask outhomography); //Draw the matched keypointsMat result =NewMat (); Features2dtoolbox.drawmatches (Modelimage, modelkeypoints, Observedimage, observedkeypoints, matches, res Ult,NewMcvscalar (255,255,255),NewMcvscalar (255,255,255), mask); #regionDraw the projected region on the imageif(Homography! =NULL)                {                    //draw a rectangle along the projected modelRectangle rect =NewRectangle (Point.empty, modelimage.size); Pointf[] pts=Newpointf[] {NewPointF (rect. Left, rect. Bottom),NewPointF (rect. Right, rect. Bottom),NewPointF (rect. Right, rect. TOP),NewPointF (rect. Left, rect.                    TOP)}; PTS=Cvinvoke.perspectivetransform (pts, homography); Point[] Points= array.convertall<pointf, point>(pts, point.round); using(Vectorofpoint VP =NewVectorofpoint (points)) {Cvinvoke.polylines (result, VP,true,NewMcvscalar (255,0,0,255),5); }                }                #endregion                returnresult; }        }

SURF Characteristic method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.