我想获取包含每个路径的开始和结束坐标的拉直线列表。
有了canny和sift,我得到了坐标,但是没有命令,对我来说就没用了
所以我决定通过HoughLinesP画线,但是如何分隔线并获取其坐标呢?
img = cv2.imread(path)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
contours, hierarchy = cv2.findContours(
# gray, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
# gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
canny = cv2.Canny(gray, 50, 200)
cv2.imshow("canny", canny)
# cv2.imwrite(path[:-4] + '.png', canny)
lines = cv2.HoughLinesP(image=canny,
rho=1,
theta=np.pi/180,
threshold=10,
lines=np.array([]),
minLineLength=50/2,
maxLineGap=260
)
a, b, c = lines.shape
for i in range(a):
cv2.line(img,
(lines[i][0][0], lines[i][0][1]),
(lines[i][0][2], lines[i][0][3]),
(0, 0, 255),
2,
cv2.LINE_AA
)
cv2.imshow('houghlines', img)