''' 角点检测:平直棱线的交汇点(颜色梯度方向改变的像素点的位置) OpenCV提供的角点检测相关API: gray = cv.cvtColor(original, cv.COLOR_BGR2GRAY) # Harris角点检测器 # 边缘水平方向、垂直方向颜色值改变超过阈值7、5时即为边缘 # 边缘线方向改变超过阈值0.04弧度即为一个角点。 corners = cv.cornerHarris(gray, 7, 5, 0.04) ''' import cv2 as cv original = cv.imread('./ml_data/box.png') cv.imshow('Original', original) gray = cv.cvtColor(original, cv.COLOR_BGR2GRAY) cv.imshow('Gray', gray) coners = cv.cornerHarris(gray, 7, 5, 0.04) coners = cv.dilate(coners, None) mixture = original.copy() cv.imshow('Coners', coners) mixture[coners > coners.max() * 0.1] = [0, 0, 255] cv.imshow('Mixture', mixture) cv.waitKey()