import numpy as np
import cv2
import matplotlib.pyplot as plt
img = cv2.imread("rili.jpg",0)
edges = cv2.Canny(img,50,150)
plt.imshow(edges,cmap=plt.cm.gray)
lines = cv2.HoughLines(edges,0.8,np.pi/180,150)
for line in lines:
rho, theta = line[0]
a = np.cos(theta)
b = np.sin(theta)
x0 = rho*a
y0 = rho*b
x1 = int(x0+1000*(-b))
y1 = int(y0+1000*a)
x2 = int(x0-1000*(-b))
y2 = int(y0-1000*a)
cv2.line(img,(x1,y1),(x2,y2),(0,255,0))
plt.imshow(img[:,:,::-1])
python霍夫直线检测
最新推荐文章于 2024-08-15 16:53:08 发布