Learning opencv Lecture 7 (detecting and matching interest points)

Source: Internet
Author: User
Tags scalar

In this chapter, we will cover:

  • Detecting Harris corners
  • Detecting fast features
  • Detecting the scale-invariant surf features
  • Describing surf features

 

Detecting Harris corners

The basic opencv function for detecting Harris corners is called CV: cornerharrisand is straightforward to use. you call it on an input image and the result is an image of floats which gives the corner strength at each pixel location. A threshold is then applied on this output image in order to obtain a set of detected corners. this is accomplished by the following code:

// Detect Harris Cornerscv::Mat cornerStrength;cv::cornerHarris(image, cornerStrength,3,// neighborhood size3,// aperture size0.01// Harris parameter);// threshold the corner strengthscv::Mat harrisCorners;double threshold = 0.0001;cv::threshold(cornerStrength, harrisCorners, threshold, 255, cv::THRESH_BINARY_INV);cv::imshow("Original Image", image);cv::imshow("Harris Corner Map", harrisCorners);

Here is the original image:

 

 

The result is a binary map image shown in the following screenshot which is inverted for better viewing (that is, We used CV: interval of CV: thresh_binaryto get the detected corners in black):

 

The class encapsulates the Harris parameters with their default values and corresponding getter and setter methods (which are not shown here ):

#if !defined HARRISDETECTOR#define HARRISDETECTOR#include <core/core.hpp>#include 

Using this class, the detection of the Harris points is accomplished as follows:

// Using HarrisDetector Class// Create Harris detector instanceHarrisDetector harris;// Compute Harris valuesharris.detect(image);// Detect Harris cornersstd::vector<cv::Point> pts;harris.getCorners(pts, 0.01);// Draw Harris cornersharris.drawOnImage(image, pts);cv::imshow("Harris Corners", image);

Which results in the following image:

Additional improvements can be made to the original Harris corner algorithm. this section describes another corner detector found in opencv which expands the Harris detector to make its corners more uniformly distributed into ss the image. as we will see, this operator has an implementation in the new opencv 2 common interface for Feature Detector.

Good features to track:

// Compute good features to trackstd::vector<cv::Point2f> corners;cv::goodFeaturesToTrack(image,corners,    500, // maximum number of corners to be returned    0.01, // quality level    10); // minimum allowed distance between points

In addition to the quality-level threshold value, and the minimum tolerated distance between interest points, the function also uses a maximum number of points to be returned (this is possible since points are accepted in order of strength ). the preceding function call produces the following result:

  

 

Detecting fast features

In this recipe, we present another feature point operator. this one has been specifically designed to allow quick detection of interest points in an image. the describe to accept or not to accept a keypoint being based on only a few pixel comparisons.

Using the opencv 2 common interface for feature point detection makes the deployment of any feature point detectors easy. the one presented in this recipe is the fast detector. as the name suggests, it has been designed to be quick to compute. note that opencv also proposes a generic function to draw keypoints on an image:

// Detection FAST featuresimage = cv::imread("../church01.jpg");// vector of keypointsstd::vector<cv::KeyPoint> keypoints;// Construction of the Fast feature detector objectcv::FastFeatureDetector fast(40); // threshold for detection// feature point detectionfast.detect(image, keypoints);// draw keypoints on an imagecv::drawKeypoints(image,//original imagekeypoints,// vector of keypointsimage,// the output imagecv::Scalar(255, 255, 255),// key point colorcv::DrawMatchesFlags::DRAW_OVER_OUTIMG // drawing flag);cv::imshow("FAST Features", image);

By specifying the chosen drawing flag, the keypoints are drawn over the output image, thus producing the following result:

 

Detecting the scale-invariant surf features

The opencv Implementation of surf features also use the CV: featuredetector interface. Therefore, the detection of these features is similar to what we demonstrated in the previous recipes of this chapter:

 

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.