import cv2
import numpy as np
class corn_detector:
def __init__(self,input_file='box.png'):
self.img = cv2.imread(input_file)
def corn_dector(self):
img=self.img
cv2.imshow('Input image', self.img)
img_gray = cv2.cvtColor(self.img, cv2.COLOR_BGR2GRAY)
#将图像转为灰度,并将其强制转换为浮点值。浮点值将用于棱角检测过程
img_gray = np.float32(img_gray)
#对灰度图像运行哈里斯角检测器(Harris corner detector)函数
img_harris = cv2.cornerHarris(img_gray, 7, 5, 0.04)
#为了标记棱角,需要放大图像
img_harris = cv2.dilate(img_harris, None)
#定义显示重要点个数的阈值
img[img_harris > 0.01 * img_harris.max()] = [0, 0, 0]
cv2.imshow('Harris Corners', img)
cv2.waitKey()
test=corn_detector()
test.corn_dector()
热门工具 换一换