我想通过在它们之间距离最短的点之间画一条线来链接图像的两个近端点。我尝试了连接散点的方法,但这不适用于我的代码。我使用 Shi-Tomasi 角点检测来绘制角点。import cv2import numpy as npfrom matplotlib import pyplot as pltimport cv2 as cvfrom scipy.spatial import distanceimg = cv2.imread('edge.png', cv2.IMREAD_GRAYSCALE)rows, cols = img.shapecanny = cv2.Canny(img, 50, 240)kernel = np.ones((5,5),np.uint8)dilation = cv2.dilate(canny,kernel,iterations = 1)size = np.size(img)skel = np.zeros(img.shape,np.uint8)element = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3))skel = cv2.bitwise_or(skel,dilation)corners = cv2.goodFeaturesToTrack(skel,30,0.01,11)corners = np.int0(corners)for i in corners: x,y = i.ravel() cv2.circle(img,(x,y),3,255,-1)print(corners)plt.imshow(img),plt.show()cv2.imshow('Original', dilation)cv2.imshow('canny', canny)我有图像的端点。我只想用一条线连接最近的端点。如上图所示,我手动尝试了它。
添加回答
举报
0/150
提交
取消