Ejemplo n.º 1
0
def get_images_from_video(vid_fname,
                          out_path,
                          frame_interval,
                          logger=Logger.get_stdout_logger()):
    utils.file_exists(vid_fname, exit_=True)
    utils.folder_exists(out_path, exit_=False, create_=True, print_=True)

    logger.info(" # Extract image from video, {}".format(vid_fname))

    vid = mpy.VideoFileClip(vid_fname)
    base_fname = os.path.splitext(os.path.basename(vid_fname))[0]
    i_digit = int(np.log10(vid.duration / frame_interval)) + 1
    n_digit = int(np.log10(vid.duration)) + 3

    for i, s in enumerate(itools.numeric_range(0, vid.duration,
                                               frame_interval)):
        frame = vid.get_frame(s)
        time_info = "__" + \
                    "{:0{width}d}".format(i, width=i_digit) + \
                    "__" + \
                    "{:0{width}.1f}sec".format(s, width=n_digit)
        out_fname = os.path.join(out_path,
                                 base_fname + time_info + IMAGE_FILE_EXT)
        utils.imwrite(frame, out_fname)
        logger.info(" # save image, {}".format(out_fname))
Ejemplo n.º 2
0
    def __init__(self, camera_info, sim_save_dir, logger):
        self.pd_info_dict = dict()
        self.camera_info = camera_info
        self.sim_save_dir = sim_save_dir

        self.sim_out_dir = self.get_sim_out_dir(edge_uid, sim_save_dir)
        if os.path.isdir(self.sim_out_dir):
            shutil.rmtree(self.sim_out_dir)
        utils.folder_exists(self.sim_out_dir, create_=True)

        self.logger = logger