Opencv--brisk feature detection, matching and object finding

Source: Internet
Author: User

To detect and draw feature points:

1#include <opencv2/opencv.hpp>2#include <opencv2/xfeatures2d.hpp>3#include <iostream>4 5 using namespaceCV;6 using namespacecv::xfeatures2d;7 using namespacestd;8 9 intMainintargcChar**argv) {TenMat src = imread ("test.jpg", Imread_grayscale); One     if(Src.empty ()) { Aprintf"could not load image...\n"); -         return-1; -     } theNamedwindow ("Input Image", cv_window_autosize); -Imshow ("Input Image", SRC); -  -     //brisk feature point detection +ptr<brisk> detector = brisk::create ();//creates a brisk class object and initializes -Vector<keypoint>keypoints; +Detector->detect (SRC, keypoints, Mat ());//find the key. A  at     //Draw key points - Mat keypoint_img; -Drawkeypoints (SRC, keypoints, keypoint_img, Scalar::all (-1), Drawmatchesflags::D efault); -Imshow ("keypoints Image", keypoint_img); -  -Waitkey (0); in     return 0; -}

The:

1#include <opencv2/opencv.hpp>2#include <iostream>3#include <math.h>4 5 using namespaceCV;6 using namespacestd;7 8 intMainintargcChar**argv) {9Mat IMG1 = Imread ("fire_5.jpg", Imread_grayscale);TenMat Img2 = Imread ("number. jpg", Imread_grayscale); One     if(Img1.empty () | |Img2.empty ()) { Aprintf"could not load images...\n"); -         return-1; -     } theImshow ("Box Image", IMG1); -Imshow ("Scene Image", IMG2); -  -  +     //Extract Akaze features -ptr<brisk> detector =brisk::create (); +Vector<keypoint>keypoints_obj; AVector<keypoint>Keypoints_scene; at Mat descriptor_obj, Descriptor_scene; -Detector->Detectandcompute (IMG1, Mat (), Keypoints_obj, descriptor_obj); -Detector->Detectandcompute (Img2, Mat (), Keypoints_scene, descriptor_scene); -  -  -     //Matching inFlannbasedmatcher Matcher (NewFlann::lshindexparams ( -,Ten,2)); -     //flannbasedmatcher Matcher; to     //flannbasedmatcher Matcher; +Vector<dmatch>matches; - Matcher.match (Descriptor_obj, descriptor_scene, matches); the  *     //draw matches (key points) $ Mat akazematchesimg;Panax Notoginseng     /* - drawmatches (IMG1, Keypoints_obj, Img2, Keypoints_scene, matches, akazematchesimg); the imshow ("Akaze match result", akazematchesimg);*/ +  AVector<dmatch>goodmatches; the     DoubleMindist =100000, maxDist =0; +      for(inti =0; i < descriptor_obj.rows; i++) { -         DoubleDist =matches[i].distance; $         if(Dist <mindist) { $Mindist =Dist; -         } -         if(Dist >maxDist) { theMaxDist =Dist; -         }Wuyi     } theprintf"min Distance:%f", mindist); -  Wu      for(inti =0; i < descriptor_obj.rows; i++) { -         DoubleDist =matches[i].distance; About         if(Dist < Max (1.5*mindist,0.02)) { $ Goodmatches.push_back (Matches[i]); -         } -     } -  ADrawmatches (IMG1, Keypoints_obj, Img2, Keypoints_scene, Goodmatches, Akazematchesimg, Scalar::all (-1), +Scalar::all (-1), vector<Char>(), drawmatchesflags::not_draw_single_points); theImshow ("Good match result", akazematchesimg); -  $Waitkey (0); the     return 0; the}

Opencv--brisk feature detection, matching and object finding

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.