用openCV图像识别一条直线的代码
时间: 2023-03-13 09:43:43 浏览: 93
OpenCV实现图像的直线检测
5星 · 资源好评率100%
使用OpenCV图像识别一条直线的代码为:import cv2img = cv2.imread("image.jpg")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 75, 150)lines = cv2.HoughLinesP(edges, 1, np.pi/180, 30, maxLineGap=250)for line in lines:
x1, y1, x2, y2 = line[0]
cv2.line(img, (x1, y1), (x2, y2), (0, 255, 0), 3)cv2.imshow("Edges", edges)
cv2.imshow("Image", img)
cv2.waitKey(0)
阅读全文