【发布时间】:2021-09-22 22:44:47
【问题描述】:
我能够检测到车道,但我还必须检测到车道的中间/中心,即两条线的中心/中间。我尝试了 x1 和 x2 的中间,但它没有用。我想要第三条线,即中间线。我还附上了截图
def houghLines(cropped_canny):
return cv2.HoughLinesP(cropped_canny, 2, np.pi/180, 100,
np.array([]), minLineLength=70, maxLineGap=5)
def addWeighted(frame, line_image):
return cv2.addWeighted(frame, 0.8, line_image, 1, 1)
def display_lines(img,lines):
line_image = np.zeros_like(img)
if lines is not None:
print(len(lines))
for line in lines:
for x1, y1, x2, y2 in line:
#print(len(lines))
cv2.line(line_image,(x1,y1),(x2,y2),(0,0,255),5)
return line_image
cap = cv2.VideoCapture("videoplayback (online-video-cutter.com) (1).mp4")
while(cap.isOpened()):
_, frame = cap.read()
canny_image = canny(frame)
cropped_canny = region_of_interest(canny_image)
#cv2.imshow("cropped_canny",cropped_canny)
lines = houghLines(cropped_canny)
#averaged_lines = average_slope_intercept(frame, lines)
line_image = display_lines(frame, lines)
combo_image = addWeighted(frame, line_image)
cv2.imshow("result", combo_image)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
【问题讨论】:
-
你用什么等式从两条红线中得到中间线?您应该从端点获取线的方程并组合方程(组合斜率和组合截距)以获得中间线。
标签: python opencv hough-transform