Machine vision-point feature detection

Source: Internet
Author: User
Tags scalar

Feature detection and matching is a basic problem in computer vision, and Point feature detection and matching are widely used in image stitching and automatic three-dimensional reconstruction.

There are generally two ways to detect and match point features:

1 in the image search for those who use the local search method to accurately track the characteristics;

2 independent detection of feature points in all inspected images, and then matching based on their local performance;

1) is suitable for the image sequence which is photographed in a similar angle or in a fast succession, 2 is suitable for the existence of a large number of movements or changes in the image sequence.


Corner Point

Feature detection and matching is an important part of computer Vision application, which needs to find out the characteristics of the image to establish the corresponding relationship. Point, which is a special position in the image, is a common type of feature, where local characteristics can also be called "key feature Points" (KeyPoint feature), or "points of interest" (interest point), or "Corner points" (Conrner).

The specific description of the corner point can be as follows: the first derivative (that is, the gradient of gray scale), the local maximum corresponding pixel points; Two and two above the edge of the intersection point of the image gradient and gradient direction of the change rate are very high points, the first derivative at the corner point is the largest, the second derivative is zero, indicating the direction of the discontinuity of the object's edge change.

Harris Corner Detection

When a window moves on the image, in a smooth area like figure (a), the window does not change in all directions. On the edge as shown (b), the window does not change in the direction of the edge. At the corner point as shown in figure (c), the window varies in all directions. Harris Corner Detection is the use of this intuitive physical phenomenon, through the window in all directions of the degree of change, determine whether the corner point.

Translate the image window [u,v] to produce grayscale changes E (u,v)

By:, Get:

For a locally small amount of movement [u,v], the approximate expression is:

where M is the 2*2 matrix, which can be obtained by the derivative of the image:

E (u,v) of the oval-like diagram below:

Define the corner response function R as:

Harris Corner detection algorithm is the diagonal point response function R for threshold processing: R > Threshold, that is to extract the local maxima of R.


Second, OPENCV code implementation

Harris class

[cpp]  View plain copy #ifndef  HARRIS_H   #define  HARRIS_H   #include   " Opencv2/opencv.hpp "      class harris   {   private:       cv::mat  cornerstrength;  //opencv harris function Detection results, That is, the corner response function value of each pixel    the result of     cv::mat cornerth; //cornerstrength threshold value         cv::mat localmax; //Local maximum results        int  neighbourhood; //Neighborhood Window Size        int aperture;// Sobel Edge Detection window size (Sobel gets the gray derivative of x,y direction of each pixel)        double k;        double maxstrength;//Corner-point response function Max        double threshold;// Threshold Drop Response Small value        int nonmaxsize;//here is the default 3, which is the maximum suppression of the neighborhood window size         cv::mat kernel;//Maximum Value inhibitionThe core of the system, here is the expansion of nuclear    public:       harris (): Neighbourhood (3), Aperture (3), K ( 0.01), maxstrength (0.0), threshold (0.01), nonmaxsize (3) {          };           void setlocalmaxwindowsize (int nonmaxsize) {           this->nonMaxSize = nonMaxSize;        };          //Calculation of corner response function and non-maximum suppression         void detect (const cv::mat &image) {         &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//OPENCV function of corner response function                 cv::cornerHarris  (image,cornerstrength,neighbourhood,aperture,k );               double minStrength;  &nbSp             //calculates the maximum minimum response value                 cv::minMaxLoc  (cornerstrength,& minstrength,&maxstrength);                   cv::Mat dilated;                //default 3*3 core expansion, after expansion, in addition to the local maximum point and the same as the original, other nonlocal maximum point is           Maximum value point substitution            in       //3*3 neighborhood &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;CV::d ilate  (Cornerstrength,dilated,cv::mat ());                //compared to the original image, only the same points as the original value, these points are local maximum points, save to localmax                cv::compare (CornerStrength, DILATED,LOCALMAX,CV::CMP_EQ);  &nbSp     }          //Get corner map         cv::mat getcornermap (double qualitylevel)  {                cv::Mat cornerMap;                //  threshold value based on corner response maximum                 threshold= qualityLevel*maxStrength;                cv::threshold (cornerstrength,cornerth,               threshold,255,cv::thresh_binary);                //  converted to 8-bit diagram                 cornerth.convertto (cornerMap,CV_ 8U);   &NBsp;           //  and local maximum graphs, and the remaining corner-point local maximum graph, namely: complete the non-maximum suppression                cv::bitwise_and (CornerMap, LOCALMAX,CORNERMAP);               return  cornerMap;       }          void  getcorners (STD::VECTOR&LT;CV::P oint> &points,                double qualitylevel)  {                //Get corner graph                 cv::mat cornermap= getcornermap (qualitylevel);                //  Get corner           &nbsP;     getcorners (points, cornermap);       }           //  traverse full map, get corner        void  Getcorners (STD::VECTOR&LT;CV::P oint> &points,   &NBSP;&NBSP;&NBSP;&NBSP;CONST&NBSP;CV:: Mat& cornermap)  {                   for ( int y = 0; y < cornerMap.rows; y++ )  {                        const uchar* rowPtr = cornerMap.ptr<uchar> (y);                         for ( int x = 0; x < cornerMap.cols; x++ )  {                       //  not 0 point is corner point                               if  (Rowptr[x])  {                                     Points.push_back (CV::P oint (x,y));                              }                         }                    }             }          / /Circle Mark Corner        void drawonimage (cv::mat &image,     &NBSP;&NBSP;&NBSP;CONST&NBSP;STD::VECTOR&LT;CV::P oint> &points,                cv::scalar color= cv::scalar (255,255,255),                int radius=3,  int thickness=2)  {               &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;STD::VECTOR&LT;CV::P oint>::const_iterator it= Points.begin ();                        while  (It!=points.end ())  {           &nbCircled      at sp;            //  Corner Point                     cv::circle (image,*it,radius,color,thickness);                        ++it;                }       }     };      #endif  // HARRIS_H   related test code:

[CPP] View plain copy cv::mat image, Image1 = Cv::imread ("test.jpg");            Gray-scale Transformation Cv::cvtcolor (Image1,image,cv_bgr2gray);      The classic Harris corner point method Harris Harris;      Compute the corner point harris.detect (image);      Obtain corner point STD::VECTOR<CV::P oint> pts;      Harris.getcorners (pts,0.01);         Mark Corner Point Harris.drawonimage (image,pts);      Cv::namedwindow ("Harris");      Cv::imshow ("Harris", image);      Cv::waitkey (0);   return 0; Related test results:


Three, Shi-tomasi algorithm principle

From the classic Harris Corner detection method, it is not difficult to see that the stability of the algorithm and K-related, and K is an empirical value, not easy to grasp, floating may also be larger. In view of this, the improved Harris method () directly calculates two eigenvalues and classifies them directly by comparing two eigenvalues so that the Harris response function is not computed.

On the other hand, we no longer suppress with the non maxima, but choose tolerance Distance: Only one characteristic point within tolerance distance.
The algorithm first selects a point with the maximum minimum eigenvalue (i.e.: Max (min (e1,e2)), E1,e2 is the characteristic value of the Harris matrix) as the corner point, and then in order to find the remaining corner points according to the maximum minimum eigenvalue sequence, of course, and the distance from the previous corner of the tolerance distance within the new corner of the point Bai ignored.

OPENCV test the algorithm code as follows:

[CPP] View plain copy cv::mat image, Image1 = Cv::imread ("test.jpg");       Gray-scale Transformation Cv::cvtcolor (Image1,image,cv_bgr2gray);       Improved Harris Corner detection method STD::VECTOR<CV::P oint> Corners; Cv::goodfeaturestotrack (Image,corners, 200,//Corner point Maximum number 0.01,//quality level, here is 0.01*max (min (e1,e2)), E1,e2 is H       Characteristic value of Arris matrix 10); Distance tolerance between two corner points Harris (). Drawonimage (image,corners);//Mark Corner test results are as follows:


Four, fast corner point detection

The principle of the algorithm is relatively simple, but the real-time is very strong.

The corner point of the algorithm is defined as: if there is a 3/4 point on the circular neighborhood circumference of a pixel and the pixel point is different (programming does not exceed a threshold th), it is considered that the point is a candidate corner point. OpenCV more extreme, select the radius of 3 of the circumference (up and down) four points, if more than three points and the pixel point is different, then the point is a candidate corner point.

Similar to the Harris algorithm, the algorithm requires a non maxima suppression.

OpenCV Code:

[CPP] View plain copy cv::mat image, Image1 = Cv::imread ("test.jpg");   Cv::cvtcolor (Image1,image,cv_bgr2gray);   Fast corner detection std::vector<cv::keypoint> keypoints;   Cv::fastfeaturedetector Fast (40,true);   Fast. Detect (Image,keypoints); CV::d rawkeypoints (Image,keypoints,image,cv::scalar::all (255), CV::D rawmatchesflags::D raw_over_outimg);

The test results are as follows:


V. Reference documents

"1" The classical article describing the Harris Operator:c Harris and M.J Stephens, A combined corner and Edge detector , by Alvey Vision Conference, pp. 147–152, 1988.

"2" the article by J. Shi and C. Tomasi, good features to track, Int. conference on Computer Vision and pattern recognitio N, pp. 593-600, 1994 which introduced these features.

"3" the article by K. Mikolajczyk and C. Schmid, Scale and affine invariant interest point detectors, International Journa L of Computer Vision, vol. 1, pp. 63-86, which proposes a multi-scale and affine-invariant Harris operator.

"4" the article by E. Rosten and T. Drummond, Machine Learning for high-speed corner detection, in European Conference O n Computer Vision, pp. 430-443, 2006 that describes the FAST feature algorithm in detail
Link Address: http://blog.csdn.net/crzy_sparrow/article/details/7391511

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.