📜  Python|使用 OpenCV 的 Harris 角点检测方法进行角点检测

📅  最后修改于: 2022-05-13 01:55:29.108000             🧑  作者: Mango

Python|使用 OpenCV 的 Harris 角点检测方法进行角点检测

哈里斯角检测算法被开发用于识别图像的内角。图像的角落基本上被识别为在所有可能的维度和方向上梯度的大强度变化的区域。提取的角点可以是图像特征的一部分,可以与其他图像的特征进行匹配,可以用来提取准确的信息。 Harris Corner Detection 是一种从输入图像中提取角点并从输入图像中提取特征的方法。
关于使用的函数:

以下是Python实现:

Python3
# Python program to illustrate
# corner detection with
# Harris Corner Detection Method
 
# organizing imports
import cv2
import numpy as np
 
# path to input image specified and
# image is loaded with imread command
image = cv2.imread('GeekforGeeks.jpg')
 
# convert the input image into
# grayscale color space
operatedImage = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
 
# modify the data type
# setting to 32-bit floating point
operatedImage = np.float32(operatedImage)
 
# apply the cv2.cornerHarris method
# to detect the corners with appropriate
# values as input parameters
dest = cv2.cornerHarris(operatedImage, 2, 5, 0.07)
 
# Results are marked through the dilated corners
dest = cv2.dilate(dest, None)
 
# Reverting back to the original image,
# with optimal threshold value
image[dest > 0.01 * dest.max()]=[0, 0, 255]
 
# the window showing output image with corners
cv2.imshow('Image with Borders', image)
 
# De-allocate any associated memory usage
if cv2.waitKey(0) & 0xff == 27:
    cv2.destroyAllWindows()


输入:

输出: