Python 21.opencv 霍夫直线变换

import cv2
import numpy as np

img = cv2.imread('lane.jpg')
# img = cv2.imread('pic2.PNG')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 100, 200, apertureSize=3)

minlinelength = 200
maxlinegap = 20

lines = cv2.HoughLinesP(edges, 1, np.pi/180, 100, minlinelength, maxlinegap)
for line in lines:
    for x1, y1, x2, y2 in line:
        cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 6)

cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
发布了54 篇原创文章 · 获赞 41 · 访问量 7885

猜你喜欢

转载自blog.csdn.net/qq_36071362/article/details/104215972