params_cam = sensor_params["params_cam"] rospy.init_node('lane_detector', anonymous=True) image_parser = IMGParser() bev_op = BEVTransform(params_cam=params_cam) curve_learner = CURVEFit(order=1) rate = rospy.Rate(20) while not rospy.is_shutdown(): if image_parser.edges is not None: img_warp = bev_op.warp_bev_img(image_parser.edges) lane_pts = bev_op.recon_lane_pts(image_parser.edges) x_pred, y_pred_l, y_pred_r = curve_learner.fit_curve(lane_pts) curve_learner.write_path_msg(x_pred, y_pred_l, y_pred_r) curve_learner.pub_path_msg() xyl, xyr = bev_op.project_lane2img(x_pred, y_pred_l, y_pred_r) img_warp1 = draw_lane_img(img_warp, xyl[:, 0].astype(np.int32), xyl[:, 1].astype(np.int32), xyr[:, 0].astype(np.int32), xyr[:, 1].astype(np.int32))
pts_learner = CURVEFit(order=3) lane_detector = LINEDetector() rate = rospy.Rate(20) img_wlane = None while not rospy.is_shutdown(): if lane_detector.cam is not None: img_wlane = lane_detector.binary_image() if img_wlane is not None: # 카메라 이미지를 BEV이미지로 변환 img_bev = bev_trans.warp_bev_img(img_wlane) # 카메라 이미지에서 차선에 해당하는 포인트들을 추출 lane_pts = bev_trans.recon_lane_pts(img_wlane) # 추출한 포인트를 기반으로 차선을 예측 x_pred, y_pred_l, y_pred_r = pts_learner.fit_curve(lane_pts) # 예측한 차선을 Path로 변환하여 메세지의 데이터를 작성 pts_learner.write_path_msg(x_pred, y_pred_l, y_pred_r) # 예측한 차선을 publish topic: /lane_path pts_learner.pub_path_msg() # 예측한 차선 포인트들을 이미지에 넣기 위해서 변환 xyl, xyr = bev_trans.project_lane2img(x_pred, y_pred_l, y_pred_r) # 예측한 차선 포인트들을 BEV이미지에 넣기
'r') as fp: sensor_params = json.load(fp) params_cam = sensor_params["params_cam"] rospy.init_node('lane_detector', anonymous=True) image_parser = IMGParser() bev_op = BEVTransform(params_cam=params_cam) curve_learner = CURVEFit(order=3) rate = rospy.Rate(20) while not rospy.is_shutdown(): img_wlane = image_parser.get_bi_img() img_warp = bev_op.warp_bev_img(img_wlane) lane_pts = bev_op.recon_lane_pts(img_wlane) x_pred, y_pred_l, y_pred_r = curve_learner.fit_curve(lane_pts) curve_learner.write_path_msg(x_pred, y_pred_l, y_pred_r) curve_learner.pub_path_msg() xyl, xyr = bev_op.project_lane2img(x_pred, y_pred_l, y_pred_r) img_warp1 = draw_lane_img(img_warp, xyl[:, 0].astype(np.int32), xyl[:, 1].astype(np.int32), xyr[:, 0].astype(np.int32), xyr[:, 1].astype(np.int32))
bev_trans = BEVTransform(params_cam=params_cam, cut_size=0.55) # BEV로 변환된 이미지에서 추출한 포인트를 기반으로 RANSAC을 이용하여 차선을 예측하는 클래스를 선언 pts_learner = CURVEFit(order=3, init_width=0.5) lane_detector = LINEDetector() rate = rospy.Rate(20) while not rospy.is_shutdown(): if lane_detector.img_lane is not None: img_lane_pts = copy.deepcopy(lane_detector.img_lane) img_bev = copy.deepcopy(lane_detector.img_lane) # lane_detector.img_lane[:int(0.6*640), :] = 0 # 카메라 이미지를 BEV이미지로 변환 img_bev = bev_trans.warp_bev_img(img_bev) # 이진화된 카메라 이미지를 전체에서(위에서) 0.5(전체=1)만큼 자르고 나머지에서 차선에 해당하는 포인트들을 추출 lane_pts = bev_trans.recon_lane_pts(img_lane_pts) # print(lane_pts[1]) pts_learner.init_setting(lane_pts) # 추출한 포인트를 기반으로 차선을 예측 x_pred, y_pred_l, y_pred_r = pts_learner.fit_curve(lane_pts) # 예측한 차선을 Path로 변환하여 메세지의 데이터를 작성 pts_learner.write_path_msg(x_pred, y_pred_l, y_pred_r) # 예측한 차선을 publish topic: /lane_path pts_learner.pub_path_msg() # 예측한 차선 포인트들을 이미지에 넣기 위해서 변환 xyl, xyr = bev_trans.project_lane2img(x_pred, y_pred_l, y_pred_r)
with open(os.path.join(currentPath, 'sensor/sensor_params.json'), 'r') as fp: sensor_params = json.load(fp) params_cam = sensor_params["params_cam"] rospy.init_node('lane_detector', anonymous=True) image_parser = IMGParser() bev_op = BEVTransform(params_cam=params_cam) curve_learner = CURVEFit(order=3) rate = rospy.Rate(20) while not rospy.is_shutdown(): if image_parser.img_wlane is not None: img_warp = bev_op.warp_bev_img(image_parser.img_wlane) lane_pts = bev_op.recon_lane_pts(image_parser.img_wlane) x_pred, y_pred_l, y_pred_r = curve_learner.fit_curve(lane_pts) curve_learner.write_path_msg(x_pred, y_pred_l, y_pred_r) curve_learner.pub_path_msg() xyl, xyr = bev_op.project_lane2img(x_pred, y_pred_l, y_pred_r) img_warp1 = draw_lane_img(img_warp, xyl[:, 0].astype(np.int32), xyl[:, 1].astype(np.int32), xyr[:, 0].astype(np.int32), xyr[:, 1].astype(np.int32)) #cv2.imshow("lane_detector", img_warp1)