Image algorithm Test Iteratoralgorithmfeatures
Original articles, reproduced please specify the source: http://blog.csdn.net/crzy_sparrow/article/details/7391511
Article directory:
First, Harris Angle point detection basic theory
Second, OPENCV code implementation
Third, improved Harris corner point detection
Four, fast corner point detection
V. References
Vi. Appendices (information and source code)
First, Harris Corner Point Detection basic theory (to clarify too many things, the appendix provides documentation detailed description)
1.1 Brief expression:
Corner point: The most intuitive impression is the horizontal, vertical two in the direction of a large change in the point, that is, IX, iy are larger
Edge: Only in the horizontal, or only in the vertical direction of a larger change, that IX and IY only one of the larger
Flat area: The amount of change in the horizontal and vertical direction is small, that is, IX, iy are smaller
Corner-point Response
R=det (M)-k* (Trace (M) ^2) (appendix data gives K=0.04~0.06,opencv points out to be 0.05-0.5, floating larger)
Det (m) =λ1*λ2 Trace (m) =λ1+λ2
R depends on the characteristic value of M, for corner points | r| large, flat area | The r| is small and the edges R is negative.
1.2 Detailed Description: see the Appendix in the PPT
1.3 Algorithm steps
Among them, the local maximum can be expanded after the first comparison with the original method to obtain, see the two sources in detail.
Second, OPENCV code implementation
Harris class
#ifndef harris_h#define harris_h#include "OPENCV2/OPENCV.HPP" class Harris{private:cv::mat cornerstrength; OPENCV Harris function test results, that is, the corner response function value of each pixel Cv::mat Cornerth; The results of Cornerstrength thresholding Cv::mat Localmax; Local maximum result int neighbourhood; Neighborhood window size int aperture;//sobel edge detection window size (Sobel gets the grayscale derivative of each pixel point x, y direction) double K; Double maxstrength;//corner response function Maximum double threshold;//threshold drop response Small value int nonmaxsize;//This takes the default 3, which is the neighborhood window size of the maximum suppression Cv::mat Kern el;//the nucleus of the maximum inhibition, here is the expansion of the 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; }; Calculates the corner response function and the non-maximum suppression void Detect (const Cv::mat &image) {//OPENCV comes with the corner response function calculation function Cv::cornerharris (IMAGE,CORNERSTRENGTH,NEIGHBOURHOOD,APERTURE,K); Double minstrength; 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 original same, the other non-local maximum point is replaced by the largest point in the//3*3 neighborhood CV::d ilate (Cornerstrength,dilated,cv::mat ( )); Compared with the original image, only the same points as the original values, these points are local maximum points, saved to Localmax Cv::compare (CORNERSTRENGTH,DILATED,LOCALMAX,CV::CMP_EQ); }//Get corner plot Cv::mat getcornermap (double qualitylevel) {Cv::mat cornermap; The threshold value is calculated based on the angular response maximum threshold= qualitylevel*maxstrength; Cv::threshold (Cornerstrength,cornerth, threshold,255,cv::thresh_binary); Convert to 8-bit diagram Cornerth.convertto (cornermap,cv_8u); and the local maximum graph and the left corner local maximum graph, i.e.: complete non-maximum suppression cv::bitwise_and (CORNERMAP,LOCALMAX,CORNERMAP); return cornermap; } void Getcorners (STD::VECTOR<CV::P oint> &points, double qualitylevel) {//Get corner plot Cv::mat cornermap= Getcornermap (qualitylevel); Get corner point Getcorners (points, cornermap); }//Traverse full map to get corner pointsvoid Getcorners (STD::VECTOR<CV::P oint> &points, const 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; + +) {//Not 0 point is corner point if (Rowptr[x]) { Points.push_back (CV::P oint (x, y)); }}}}//Use the circle to mark the corner point void Drawonimage (Cv::mat &image, const STD::VEC TOR<CV::P oint> &points, cv::scalar color= cv::scalar (255,255,255), int radius=3, int thick ness=2) {std::vector<cv::P oint>::const_iterator it=points.begin (); while (It!=points.end ()) {//Corner point circled cv::circle (image,*it,radius,color,thickness); ++it; }}}; #endif//Harris_h
Related Test code:
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; Calculates the corner point harris.detect (image); Get 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:
Third, improved Harris corner point detection
From the classical Harris angle point detection method is not difficult to see, the stability of the algorithm and K, and K is an empirical value, not good 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 non-maxima, and choose tolerance Distance: There is only one feature point within the tolerance distance.
The algorithm first selects a point with the maximum minimum eigenvalue (that is: Max (min (e1,e2)), E1,e2 is the characteristic value of the Harris matrix) as a corner point, then finds the remaining corner points sequentially according to the maximum minimum eigenvalue order, and of course, the distance from the previous corner is ignored in the new corner of tolerance distance.
OPENCV test the algorithm code as follows:
Cv::mat image, Image1 = Cv::imread ("test.jpg"); Gray-scale Transformation Cv::cvtcolor (Image1,image,cv_bgr2gray); Improved method for detecting Harris Corner point std::vector<cv::P oint> Corners; Cv::goodfeaturestotrack (Image,corners, max, ///Corner number 0.01,// quality level, here is 0.01*max (min (e1,e2)), E1, E2 is the characteristic value of the Harris matrix ; Distance tolerance between two corners Harris (). Drawonimage (image,corners);//Mark Corner Point
The test results are as follows:
Four, fast corner point detection
The principle of the algorithm is simple, but real-time is very strong.
The corner of the algorithm is defined as: if there are 3/4 points on the circle circumference of a pixel and the pixels are different (no more than a threshold th), the point is considered to be the candidate corner point. OpenCV more extreme, select a radius of 3 on the circumference (up or down) four points, if more than three points and the pixel point is different, then the point is the candidate corner.
Similar to the Harris algorithm, this algorithm requires a non-maximal value suppression.
OpenCV Code:
Cv::mat image, Image1 = Cv::imread ("test.jpg"); Cv::cvtcolor (Image1,image,cv_bgr2gray); Fast angular point 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. References
"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, no 1, pp. 63-86, 2004, 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, describes the FAST feature algorithm in detail
Vi. Appendices
I pass the resources link, source code and related documents.
http://download.csdn.net/detail/crzy_sparrow/4170311
OPENCV Study Notes--harris corner Point detection