Exemple #1
0
def img_processor_test():
    vp = VideoProcessor()

    # 处理视频
    vid_path = os.path.join(DATA_DIR, 'videos', 'test.mp4')
    out_vid_path = os.path.join(
        DATA_DIR, 'videos', 'test.out.{}.mp4'.format(get_current_time_str()))
    vp.process_video(vid_path, out_vid_path)
def matchstick_api_test():
    """
    火柴人API测试
    """
    custom_png_path = os.path.join(DATA_DIR, 'custom', 'x.png')
    custom_png = cv2.imread(custom_png_path,
                            cv2.IMREAD_UNCHANGED)  # 注意OpenCV格式
    skt_idx = 0  # 火柴人模板的索引

    sm = SkeletonMain()
    head_png, custom_png, o_gif_path = sm.generate_matchstick_api(
        custom_png=custom_png, skt_idx=skt_idx)

    # 生成的结果
    head_png_path = os.path.join(DATA_DIR, 'tmp',
                                 'head.{}.png'.format(get_current_time_str()))
    custom_png_path = os.path.join(
        DATA_DIR, 'tmp', 'custom.{}.png'.format(get_current_time_str()))

    cv2.imwrite(head_png_path, head_png)
    cv2.imwrite(custom_png_path, custom_png)
    print('[Info] Gif的路径: {}'.format(o_gif_path))
def skeleton_main_for_gif_test():
    """
    测试写入gif
    """
    frame_shape = (1024, 576, 4)  # 背景尺寸
    fps = 24  # FPS
    o_gif_path = os.path.join(DATA_DIR,
                              'img_gif.{}.gif'.format(get_current_time_str()))
    skt_file = os.path.join(DATA_DIR, 'skt_file.20191119145920.m.txt')

    img_png_path = os.path.join(DATA_DIR, 'custom', 'trans.png')
    img_draw_path = os.path.join(DATA_DIR, 'custom', 'x.png')
    img_config_path = os.path.join(DATA_DIR, 'configs', 'parts_config.json')

    # 生成PNG
    png_parts = SkeletonGenerator.generate_body_parts(img_png_path,
                                                      img_draw_path,
                                                      img_config_path)

    # 写入视频
    SkeletonMain.write_gif_with_parts(o_gif_path, skt_file, fps, frame_shape,
                                      png_parts)
    def generate_matchstick_api(self, custom_png, skt_idx):
        """
        生成火柴人运动的API
        :param custom_png: 用户的PNG
        :param skt_idx: 骨骼ID
        :return: 头部的PNG, 用户的PNG, Gif存储路径
        """
        img_draw = custom_png
        img_bkg = cv2.imread(self.skeleton_bkg, cv2.IMREAD_UNCHANGED)
        png_parts = SkeletonGenerator.generate_body_parts(
            img_draw, img_bkg, self.skeleton_config)

        head_png = png_parts[0]

        skt_file = self.skt_templates[skt_idx]

        # 写入视频
        o_gif_path = os.path.join(
            DATA_DIR, 'tmp',
            'matchstick.{}.gif'.format(get_current_time_str()))
        SkeletonMain.write_gif_with_parts(o_gif_path, skt_file, self.fps,
                                          self.frame_shape, png_parts)

        return head_png, custom_png, o_gif_path
 def __init__(self):
     self.gp = GazePredicter()  # 目光预测
     self.frames_dir = os.path.join(VIDS_DIR, 'frames')
     self.out_path = os.path.join(
         VIDS_DIR, 'out.{}.mp4'.format(get_current_time_str()))
     mkdir_if_not_exist(self.frames_dir)