"""
功能:导入图片,进行边缘检测,并显示
"""
import cv2
import numpy as np
class MainWindow():
def __init__(self):
super().__init__()
img = cv2.imread("D:/Users/xuyf2/Desktop/project_C/cap_2/2cp1638667968.jpg")
img = img[357:517, 613:779] # 左侧矩形
scr1 = cv2.medianBlur(img, 5)
gray = cv2.cvtColor(scr1, cv2.COLOR_BGR2GRAY)
gray = cv2.medianBlur(gray, 5)
# Otsu方法
t2, dst2 = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)
cv2.imshow("3", dst2)
edges = cv2.Canny(dst2, 150, 400, L2gradient=False)
cv2.imshow("bianyuanjiance", edges)
gra = np.float32(edges)
corners = cv2.goodFeaturesToTrack(gra, 50, 0.1, 70)
# corners = cv2.goodFeaturesToTrack(gra, 50, 0.1, 40)
corners = np.int0(corners)
coordinate = []
zuobiaos = []
for i in corners:
x, y = i.ravel()
coordinate0 = [x, y]
zuobiaos.append([x, y])
coordinate.append(coordinate0)
photo_jiaodian = cv2.circle(gray, (x, y), 4, (0, 0, 255), -1)
cv2.imshow("jiaodian", photo_jiaodian)
if __name__ == '__main__':
mainWindow = MainWindow()
cv2.waitKey(0)
cv2.destroyAllWindows()
|