First entry to SLAM (4) - Shi-Tomasi corner detection

Reference

https://docs.opencv.org/4.x/d4/d8c/tutorial_py_shi_tomasi.html

GO

In the first entry into SLAM (1) - Harris corner detection , we introduced Harris corner detection in detail. Now is the time to learn Shi-Tomasi.
In (1), we get Harris' scoring function is R = λ 1 λ 2 − k ( λ 1 + λ 2 ) 2 = det ⁡ ( M ) − k ( trace ⁡ ( M ) ) 2 R=\lambda_1\ lambda_2-k(\lambda_1+\lambda_2)^2=\operatorname{det}(M)-k(\operatorname{trace}(M))^{2}R=l1l2k ( λ1+l2)2=give ( M )k(trace(M))2
For the Shi-Tomasi corner point, the scoring function is changed to:
R = min ( λ 1 , λ 2 ) R=min(\lambda_1,\lambda_2)R=min ( l1,l2)
is greater than a threshold, it is considered a corner.
insert image description here
The green part of the above figure,λ 1 and λ 2 \lambda_1 and \lambda_2l1and lambda2are greater than the threshold, and points falling within it are considered corner points.

the code

# -*-coding:utf-8-*-
import copy
import numpy as np
import cv2

filename = '1.jpg'
img = cv2.imread(filename)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
original = cv2.imread(filename)
cv2.imshow('original', original)
corners = cv2.goodFeaturesToTrack(gray, maxCorners=1000, qualityLevel=0.01, minDistance=10, useHarrisDetector=False)
corner_image = copy.deepcopy(original)
for i in corners:
    x,y = i.ravel()
    cv2.circle(corner_image, (x, y), 2, (0, 0, 255), -1)
cv2.imshow('out.jpg', corner_image)
cv2.waitKey(0)


We only need to pay attention to the cv2.goodFeaturesToTrack() function. When the useHarrisDetector is True, it is for Harris corner detection, and for False, it is for Shi-Tomasi corner detection.

Guess you like

Origin blog.csdn.net/REstrat/article/details/127043309