CV's key point detection

Don’t blame the foundation for moving here, just learn for yourself~~

When there are corner points in the image, there are points at the edge of the object or points at some special positions. Corner Detection is a method for obtaining image features in a computer vision system. It is a method for motion detection, image matching, video tracking, three-dimensional The basis for reconstruction and object recognition.

Here we introduce the principles of several corner detection methods commonly used in opencv and their implementation based on C++.

Harris corner detection

Harris corner principle: set a rectangular frame, place the rectangular frame in the image, sum the pixels in the rectangular frame, and then move the rectangular frame. There are Harris corners inside the box.

Where it usually appears: at the endpoint of a straight line, at the intersection of a straight line, at the inflection point of a straight line.

However, if it is detected according to the above detection principle, it will be very troublesome. It is difficult to determine the direction of movement of the rectangular frame and the specific position of the corner point when there is a corner point in the frame.

Therefore, the following methods are generally used for detection in the program: 1. Define the Harris corner detection function as:

Where M is the gradient covariance matrix, expressed as the following formula:

3. Then use the Harris corner evaluation function to judge whether there are corners in the rectangular frame:

Where det is the determinant of the matrix, k is a custom constant, and tr is the trace of the matrix. Using the above method to calculate the calculation consumes a lot, so use the following method to evaluate:  

Where λ is the eigenvector of the gradient covariance matrix M. According to this evaluation coefficient, there may be corners in the rectangular frame when the evaluation coefficient is large, but there must be no corners in the holding frame when the evaluation coefficient is small. The specific reason is as shown in the figure below, when both λ1 and λ2 have a large value, it can be determined that there must be a corner point, and when one of the values ​​​​is much larger than the other, it will also make the R value very large, but it is very difficult at this time It may be located in the "edge" area, and the evaluation accuracy also has a lot to do with the custom constant k. The code for Harris corner detection is as follows:  

Running result:  Shi-Tomas corner detection

In the Harris corner calculation method introduced in the previous section, we finally found that there is a problem: the accuracy of corner detection has a lot to do with the custom constant k, Shi-Tomas corner detection is for Harris corner This issue has been improved by redefining the evaluation coefficient calculation method:

According to this evaluation function, the evaluation coefficient takes the smaller value of λ1 and λ2, and then uses R to compare with the custom threshold. When the smaller eigenvectors all meet the conditions, the point must be a corner point .

As shown in the figure below, when the smaller eigenvectors meet the conditions, the corner area is the green area in the figure, which must be a corner point, while the orange area in the figure may be located at the edge, and the gray area must not be a corner point.

The Shi-Tomas corner detection code is as follows:  

 operation result:

Sub-pixel level corner position optimization

Through the above corner point detection algorithm, although the position of the corner point can be detected in the original image, if you observe the function carefully, you can find that the detected corner point coordinates are all integer values. This is because the image is composed of pixels and is a discrete If we want to get finer corner coordinates, we need to optimize the corner position.

The principle of optimization is shown in the figure below. When a pixel point q is a corner point, it is a local maximum value near its own field, with q as the starting point and a point p1 or p0 around it as the end point to form a vector, and calculate the gradient. At this time, the product of the vector and the gradient should be 0

When the corner point is detected in opencv (the position of the corner point at this time is not accurate), we will continue to adjust the position of the corner point q according to this principle until a certain accuracy or number of iterations is reached.

In the actual calculation process, it is usually calculated by the following formula:

It is to sum the product of q and the surrounding point vector and gradient. When the sum is less than a certain value, it is judged to have reached a certain accuracy.

The sub-pixel level corner position optimization code is as follows:

 Running result: You can see that the optimized corner position has a decimal point, indicating that its position has been optimized.

FAST corner detection

Compared with other corner detection methods, the accuracy of FAST corner detection method is relatively low, but the advantages of FAST are also very obvious, just like its name - FAST, it is fast, it has fast calculation speed and low resource consumption. It is widely used in situations with limited computing resources (such as SLAM robots based on embedded devices).

The principle of FAST corner detection is as follows:

1. Randomly select a point p in the image, assuming its pixel value is Ip

2. Draw a circle with a radius of 3, covering 16 pixels around point p, as shown in the figure below

3. Set the threshold t. If the pixel values ​​of n consecutive pixels among the 16 surrounding pixels are all smaller than (Ip−t) or larger than (Ip+t), then it is judged that point p is a corner point. In the OpenCV implementation n takes the value of 12 (3/4 of the 16-pixel perimeter).

4. A faster improvement is: first detect the four points around point p, that is, whether three points among the four points 1, 5, 9, and 12 satisfy Ip+t, and if not, skip directly , if it is satisfied, then continue to use the previous algorithm to judge whether 12 of the 16 points satisfy the condition. The FAST corner detection code is as follows:  The running results are as follows:  The disadvantages of FAST are also obvious:

1. Does not have scale invariance

2. Does not have rotation invariance

3. Susceptible to noise

The ORB feature point detection has been specially improved to address the above shortcomings, making FAST more robust while maintaining the advantage of fast computing speed.

ORB feature with point detection

The full name of ORB is ORiented Brief, which combines FAST corner detection with BRIEF feature description and improves it:

(1) To solve the rotation invariance of the BRIEF algorithm, it is necessary to calculate the main direction of the feature points. ORB uses the center of gravity to calculate, as follows (where (x, y) is a point within the feature neighborhood):

1. Calculate the moment of the image

2. Calculate the centroid of the rectangular area

3. Connect the FAST corner point and the centroid to get the direction vector 

The obtained θ value is the main direction of the FAST feature point.

(2) BRIEF descriptor, which is a binary-coded descriptor, abandons the traditional method of using regional gray histograms to describe feature points, and greatly speeds up the establishment of feature descriptors.

Taking the feature point as the center, take the neighborhood window of SxS. Randomly select a pair (two) points in the window, compare the size of the two pixels, and perform the following binary assignment.

Randomly select n pairs of random points in the window, rotate them, and then perform discrimination, and then repeat the binary assignment of the above steps to form a binary code, which is the description of the feature points, that is, the feature descriptor. (generally N=256)

ORB feature point detection code is as follows:

operation result: 

Summarize

Very commonly used and classic feature detection algorithms include SIFT and SUFT algorithms. These two algorithms are patent-pending and not commercially available. When implementing in opencv, you need to configure the opencv_contrib extension package first, then include the header file, and then initialize the method with the ORB Detection is similar to Ptrsift = SIFT::create.

About SIFT feature point detection by Baidu

Other detection methods will not expand too much

 whaosoft you are going to  http://143ai.com

Guess you like

Origin blog.csdn.net/qq_29788741/article/details/132307311