def canny_edge_detector(image): gray_image = cv2.cvtColor(image, cv2.COLOR_RGB2GRAY) blur = cv2.GaussianBlur(gray_image, (5, 5), 0) canny = cv2.Canny(blur, 50, 150) return cannycap = cv2.VideoCapture(0 + cv2.CAP_DSHOW)fourcc = cv2.VideoWriter_fourcc(*'XVID')while cap.isOpened(): _, frame = cap.read() canny_image = canny_edge_detector(frame) cropped_image = region_of_interest(canny_image)# lines = cv2.HoughLinesP(cropped_image, 2, np.pi / 180, 100, np.array([]), minLineLength=40, maxLineGap=5)# averaged_lines = average_slope_intercept(frame, lines)# line_image = display_lines(frame, averaged_lines)# combo_image = cv2.addWeighted(frame, 0.8, line_image, 1, 1) cv2.imshow("results", canny_image) if cv2.waitKey(1) & 0xFF == ord('q'): breakcap.release()cv2.destroyAllWindows()
调用摄像头_调用摄像头实时图像处理
最新推荐文章于 2023-03-04 14:24:42 发布