Harris corner detection in opencv

cv2.cornerHarris () function

cv2.cornerHarris(src, blockSize, ksize, k, dst=None, borderType=None)

src: The data type of the input image float32
blockSize: Size of the area considered in the corner detection
ksiz to: Sobel find use in guiding the window size
k: Harris corner detection of free parameters in the equation, the value for the parameter [0.04 0.06]
dst: Output image
borderType: Type of border

import cv2 
import numpy as np

img = cv2.imread('test_1.jpg')
print ('img.shape:',img.shape)#img.shape: (800, 1200, 3)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
#cv2.cornerHarris()函数的返回值其实就是R值构成的灰度图像,灰度图像坐标会与原图像对应  
#R值就是角点分数,当R值很大的时候就可以认为这个点是一个角点,所以可以通过选取值更大的点,来更精确的检测角点
dst = cv2.cornerHarris(gray, 2, 3, 0.04)
print ('dst.shape:',dst.shape)#dst.shape: (800, 1200)
img[dst>0.01*dst.max()]=[0,0,255]
cv2.imshow('dst',img) 
cv2.waitKey(0) 
cv2.destroyAllWindows()

Here Insert Picture Description

Published 27 original articles · won praise 20 · views 1543

Guess you like

Origin blog.csdn.net/qq_39507748/article/details/104599817