Ejemplo n.º 1
0
def check_densepose_exists(args, video_idx):
    op_dir = path.join(args.output_root, args.openpose_folder, video_idx)
    json_paths = sorted(glob.glob(op_dir + '/*.json'))
    for json_path in json_paths:
        dp_path = json_path.replace(args.openpose_folder, args.densepose_folder)
        dp_path = dp_path.replace(args.openpose_postfix, args.densepose_postfix)
        if not os.path.exists(dp_path):
            remove_frame(args, start=json_path)
Ejemplo n.º 2
0
def remove_invalid_frames(args, video_idx):
    op_dir = path.join(args.output_root, args.openpose_folder, video_idx)
    #print('op_dir in remove_invalid_frames', op_dir)
    json_paths = sorted(glob.glob(op_dir + '/*.json'))
    #print('json_paths', json_paths)
    for json_path in json_paths:
        if not is_valid_frame(args, json_path):
            remove_frame(args, start=json_path)
Ejemplo n.º 3
0
def remove_isolated_frames(args, video_idx):
    op_dir = path.join(args.output_root, args.openpose_folder, video_idx)
    json_paths = sorted(glob.glob(op_dir + '/*.json'))

    if len(json_paths):
        start_idx = end_idx = get_frame_idx(json_paths[0]) - 1
        for json_path in json_paths:
            i = get_frame_idx(json_path)
            # If the frames are not consecutive, there's a breakpoint.
            if i != end_idx + 1:
                # Check if this block of frames is longer than min_n_of_frames.
                if (end_idx - start_idx) < args.min_n_of_frames:
                    remove_frame(args, video_idx, start_idx, end_idx)
                start_idx = i
            end_idx = i
        # Need to check again at the end of sequence.
        if (end_idx - start_idx) < args.min_n_of_frames:
            remove_frame(args, video_idx, start_idx, end_idx)
Ejemplo n.º 4
0
def remove_static_frames(args, video_idx):
    max_static_frames = 5  # maximum number of frames to be static
    op_dir = path.join(args.output_root, args.openpose_folder, video_idx)
    json_paths = sorted(glob.glob(op_dir + '/*.json'))
    start_idx = end_idx = 0
    keypoint_dicts_prev = None

    for json_path in json_paths:
        with open(json_path, encoding='utf-8') as f:
            keypoint_dicts = json.loads(f.read())["people"]
        is_moving = detect_motion(keypoint_dicts_prev, keypoint_dicts)
        keypoint_dicts_prev = keypoint_dicts

        i = get_frame_idx(json_path)
        if not is_moving:
            end_idx = i
        else:
            # If static frames longer than max_static_frames, remove them.
            if (end_idx - start_idx) > max_static_frames:
                remove_frame(args, video_idx, start_idx, end_idx)
            start_idx = end_idx = i
Ejemplo n.º 5
0
def extract_valid_frames(args, video_path, img_dir):
    vidcap = cv2.VideoCapture(video_path)
    success, image = vidcap.read()
    frame_count = 0
    do_write = True
    while success:
        is_key_frame = frame_count % args.n_skip_frames == 0
        write_name = path.join(img_dir, "frame%06d.jpg" % frame_count)
        # Each time it's keyframe, check whether the frame is valid. If it is,
        # all frames following it before the next keyframe will be extracted.
        # Otherwise, this block of frames will be skipped and the next keyframe
        # will be examined.
        if is_key_frame:
            do_write = is_valid_frame(args, write_name)
            if not do_write:  # If not valid, remove this keyframe.
                remove_frame(args, start=write_name)
        if do_write:
            cv2.imwrite(write_name, image)
        success, image = vidcap.read()
        frame_count += 1
    print('Video contains %d frames.' % frame_count)