File size: 1,906 Bytes
59b2a81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'''
    This file is trying to repeat the frames such the it reaches target frames needed
'''
import os, shutil, sys

if __name__ == "__main__":
    input_path = "/nfs/turbo/coe-jjparkcv/boyangwa/AVDC/AVDC_results"
    store_path = "/nfs/turbo/coe-jjparkcv/boyangwa/AVDC/AVDC_results_interpolated"
    total_frames_needed = 14

    # Handle the file folder management
    if os.path.exists(store_path):
        shutil.rmtree(store_path)
    os.makedirs(store_path)

    for video_name in sorted(os.listdir(input_path)):
        sub_input_path = os.path.join(input_path, video_name)
        sub_store_path = os.path.join(store_path, video_name)

        # Create the store place
        os.makedirs(sub_store_path)

        # Find valid image lists
        num_frames_input = 0
        for file_name in os.listdir(sub_input_path):
            if file_name.endswith("png"):
                num_frames_input += 1
        print("num_frames_input is ", num_frames_input)
        
        # Calculate needed parameters
        division_factor = total_frames_needed // num_frames_input 
        remain_frames = (total_frames_needed % num_frames_input) - 1    # -1 for adaptation

        # Define the gap
        gaps = [division_factor for _ in range(num_frames_input)]
        for idx in range(remain_frames):
            if idx % 2 == 0:
                gaps[idx//2] += 1      # Start to end order
            else:
                gaps[-1*(1+(idx//2))] += 1   # End to start order

        print("gaps is ", gaps)


        # Write to the new folder
        store_idx = 0
        for frame_idx, gap in enumerate(gaps):
            for tmp in range(gap): # Repeat copy gap num of times
                img_path = os.path.join(sub_input_path, str(frame_idx)+".png")
                shutil.copyfile(img_path, os.path.join(sub_store_path, str(store_idx)+".png"))
                store_idx += 1