def save_image_and_steering_angle(video_file, output_path): lane_follower = HandCodedLaneFollower() cap = cv2.VideoCapture(video_file + '.avi') try: i = 4646 while cap.isOpened(): _, frame = cap.read() final_frame , control_ang, ang_deg = lane_follower.follow_lane(frame) cv2.imwrite(output_path + "%s_%03d_%03d.png" % ("video", i, ang_deg), frame) i += 1 if cv2.waitKey(1) & 0xFF == ord('q'): break finally: cap.release() cv2.destroyAllWindows()
def __init__(self, settings, pkg_dir): self.settings = settings print("Creating Directory Structure") self.base_dir = pkg_dir self.out_dir = self.base_dir + "/output/" + self.settings['subdir'] + "/" self.out_data_dir = self.out_dir + "data/" self.out_info_dir = self.out_dir + "info/" self.out_media_roads = self.out_dir + "source_media/roads/" self.out_media_backgrounds = self.out_dir + "source_media/backgrounds/" self.lane_follower = HandCodedLaneFollower() print("Directory generation may produce error if dir exists, or for true errors") for directory in [self.out_dir, self.out_data_dir, self.out_info_dir, self.out_media_backgrounds, self.out_media_roads]: try: os.makedirs(directory) except OSError as e: print(e) pass if settings['clear'] and raw_input('Confirm Delete Existing files in ' + settings['subdir'] +' (y/n): ') == 'y': print('Clearing Existing Files') def clear_dir(directory): for filename in os.listdir(directory): os.remove(directory + filename) clear_dir(self.out_data_dir) clear_dir(self.out_info_dir) clear_dir(self.out_media_backgrounds) clear_dir(self.out_media_roads) else: print('Not Clearing') self.media_dir = self.base_dir + "/source_media/" self.roads_dir = self.media_dir + "roads/" self.backgrounds_dir = self.media_dir + "backgrounds/" self.settings['road_images'] = [] for image_file in self.settings['road_image_files']: img = cv2.imread(self.roads_dir + image_file, cv2.IMREAD_COLOR) self.settings['road_images'].append(img) self.settings['background_images'] = [] for image_file in self.settings['background_image_files']: img = cv2.imread(self.backgrounds_dir + image_file, cv2.IMREAD_COLOR) img = cv2.resize(img, (WIDTH, HEIGHT), interpolation=cv2.INTER_AREA) self.settings['background_images'].append(img)
FOURCC = cv2.VideoWriter_fourcc(*'XVID') RECORD = False def create_video_recorder(path, width, height): return cv2.VideoWriter(path, FOURCC, 20.0, (width, height)) if __name__ == "__main__": car = ClientGenerator.CreateRCCarClient( rospy.get_param("client_context_type"), rospy.get_param("client_comm_type")) basic_cam_calc = BasicCameraCalc() lidar_calc = LidarCalc() lane_follower = HandCodedLaneFollower() status_msg = SimpleLaneFollowStatus() status_pub = rospy.Publisher("/status", SimpleLaneFollowStatus, queue_size=3) rospack = rospkg.RosPack() package_dir = rospack.get_path("auto_rc_car_demos") video_filepath = package_dir + "/training_data/video" img, dt = car.get_latest_camera_rgb() img = car.camera_to_cv_image(img) height, width, _ = img.shape datestr = datetime.datetime.now().strftime("%y%m%d_%H%M%S")