"OpenCV" Corner detection: Harris corner Point and Shi-tomasi Corner detection

Source: Internet
Author: User
Tags scalar

Corner Point

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

There are several specific descriptions of corner points:

    • The pixel points corresponding to the local maximum of the first derivative (i.e., the gradient of the grayscale);
    • Intersection of two and two edges;
    • In the image, the variation rate of gradient and gradient direction is very high.
    • The first derivative of the corner point is the largest and the second derivative is zero, which indicates the direction of discontinuity of the object's edge.
Harris Corner Point Detection

When a window is moved on the image, in the smoothing area (a), the window does not change in all directions. On the Edge (b), the window does not change in the direction of the edge. At the corner Point (c), the window changes in all directions. Harris Corner Point Detection is the use of this intuitive physical phenomenon, through the window in all directions of the degree of change, determine whether it is a corner point.

Translate the image window [u,v] to produce a grayscale change 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, it can be obtained from the derivative of the image:

The oval type of E (u,v) such as:

Define the corner response function R as:

Harris Corner Point Detection algorithm is the diagonal point response function R for threshold processing: R > Threshold, that is, the local maximum value of the extracted R.

"Related Code"

The Cornerharris function is defined in OPENCV:

void int blockSize,                                   int Double K,                                   int bordertype=border_default);  

You can combine the Convertscaleabs function to take a corner point from a threshold value:

voidCornerharris_demo (int,void*) {Mat DST, dst_norm; DST=Mat::zeros (Src.size (), CV_32FC1); ///Detector Parameters  intBlockSize =2; intAperturesize =3; DoubleK =0.04; ///Detecting CornersCornerharris (Src_gray, DST, BlockSize, Aperturesize, K, Border_default); ///normalizingNormalize (DST, Dst_norm,0,255, Norm_minmax, CV_32FC1, Mat ());     Convertscaleabs (Dst_norm, dst_norm_scaled); ///Drawing a circle around corners   for(intj =0; J < Dst_norm.rows; J + + )       {  for(inti =0; i < Dst_norm.cols; i++ )            {              if( (int) dst_norm.at<float> (j,i) >Thresh) {Circle (dst_norm_scaled, point (I, j),5, Scalar (0),2,8,0 ); Circle (Src,point (i, J),5, Scalar (255,0,0), -1,8,0 ); }            }        }        ///Showing The resultimshow (Corners_window, dst_norm_scaled);    Imshow (Source_window, SRC); }  
Shi-tomasi algorithm

The Shi-tomasi algorithm is an improvement of the Harris algorithm. The most primitive definition of the Harris algorithm is to subtract the determinant of the matrix M from the trace m, and then compare the difference with the pre-given threshold value. Later, Shi and Tomasi proposed an improved method, if the smaller one of the two eigenvalues is greater than the minimum threshold, a strong corner will be obtained.

As shown in the second image above, the eigenvalue analysis is performed on the autocorrelation matrix M, resulting in two eigenvalues and two characteristic direction vectors. Because the larger uncertainty depends on the smaller eigenvalues, that is, the search for a good feature point by finding the maximum value of the minimum eigenvalue is explained.
The methods of Shi and Tomasi are quite adequate, and in many cases, better results can be obtained than using the Harris algorithm.

"Related Code"

Since this shi-tomasi operator is proposed in 1994 in article good Features to track [1], the function name of the algorithm OpenCV implements is defined as Goodfeaturestotrack:

void Goodfeaturestotrack (inputarray image, Outputarray corners,                                       intdoubleDouble  mindistance,                                       inputarray maskint blocksize=3,                                       bool Useharrisdetector=falsedouble k=0.04 );  

The Custom usage function (to facilitate createtrackbar response) is as follows:

voidCornershitomasi_demo (int,void* )  {    if(Maxcorners <1) {maxcorners =1; } ///Parameters for Shi-tomasi algorithmVector<point2f>Corners; DoubleQualitylevel =0.01; DoubleMindistance =Ten; intBlockSize =3; BOOLUseharrisdetector =false; DoubleK =0.04; ///Copy the source imageMat Cormat; ///Apply Corner detection:D etermines strong corners on an image. goodfeaturestotrack (Src_gray, Corners, Maxcorners, Qualitylevel,                 Mindistance, Mat (), BlockSize, Useharrisdetector,    k); ///Draw Corners Detected   for(inti =0; I < corners.size (); i++) {Circle (dst_norm_scaled, corners[i],5, Scalar (255),2,8,0 ); Circle (SRC, corners[i],4, Scalar (0,255,0),2,8,0 ); }      ///Show You gotimshow (Corners_window, dst_norm_scaled);    Imshow (Source_window, SRC); }  
Practice

Define two progress bars in the main function to easily adjust the threshold value:

 namedwindow (Source_window, cv_window_autosize); Createtrackbar (  threshold:  Span style= "color: #800000;"  > ", Source_window, &thresh, Max_thresh, Cornerharris_demo); Createtrackbar (  max Corners:  Span style= "color: #800000;"      > ", Source_window, &maxcorners, Maxtrackbar, Cornershitomasi_demo);  Namedwindow (Corners_window, cv_window_autosize);  Namedwindow (Source_window, cv_window_autosize);      Imshow (Source_window, SRC); Cornerharris_demo ( 0 , 0   );  Cornershitomasi_demo ( 0 , 0 ); 

It is also necessary to say that the OpenCV 2.4.2 in the corner detection of the sample code to trace some of the problem is that the surf should no longer be defined in the Feature2d module, but legacy and nonfree, so you need to include the reference:

" opencv2/legacy/legacy.hpp " "Opencv2/nonfree/nonfree.hpp"      

Corner Point Detection results:

The blue solid point is the Harris test result, and the Green Hollow ring is the goodfeaturetotrack test result.

The graph that subtracts each pixel point after the decomposition of the M eigenvalue (that is, the graph of the Harris Threshold) is as follows:

The black solid point is the Harris threshold test result, and the White hollow ring is a threshold of 27 o'clock Shi-tomasi detection.

Reprint please indicate source: http://blog.csdn.net/xiaowei_cqu/article/details/7805206 source and information download: http://download.csdn.net/detail/ xiaowei_cqu/4466627 References:

[1] Shi and C. Tomasi. Good Features to track. Proceedings of the IEEE Conference on computer Vision and Pattern recognition, pages 593-600, June 1994.

[2] Richard Szeliski. computer vision:algorithms and applications. Springer, New York, 2010.

[3] Image feature point extraction ppt http://wenku.baidu.com/view/f61bc369561252d380eb6ef0.html

"OpenCV" Corner detection: Harris corner Point and Shi-tomasi Corner detection

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.