This repository has been archived by the owner on Sep 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_dataset.py
51 lines (41 loc) · 1.68 KB
/
create_dataset.py
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
import argparse
import os.path as path
import shutil
import sys
from helper_scripts.DataExtractor import DataExtractor
# parser for command line arguments
# -v/--vid: (string) name of video stored in ./videos
# -i/--interval: (integer) keyframe interval
# -o/-overwrite: (boolean) flag to overwrite files in ./extract/vid, default=false
parser = argparse.ArgumentParser()
parser.add_argument('-v', '--vid', required=True)
parser.add_argument('-i', '--interval', default='30')
parser.add_argument('-o', '--overwrite', action='store_true')
def main():
"""Accepts arguments and creates DataExtractor object"""
video_name = args.vid
frame_interval = int(args.interval)
overwrite = args.overwrite
# verify that video exists in ./videos
if not path.isfile(f'videos/{video_name}.mp4'):
print('--vid', video_name, "is an invalid video name, make sure video exists in ./videos")
sys.exit()
# make sure any important data does not get overwritten
if path.isfile(f'data/{video_name}.pickle'):
message = f'data/{video_name}.pickle already exists, are you sure want to overwrite it? (y/n)\n'
confirm = input(message)
while confirm != 'y' and confirm != 'n':
print('invalid input')
confirm = input(message)
if confirm == 'n':
sys.exit()
# delete ./extract/{video_name} folder
if overwrite:
shutil.rmtree(f'extract/{video_name}', ignore_errors=True)
# initialize DataExtractor object and call its methods
data_extractor = DataExtractor(video_name, frame_interval)
data_extractor.extract()
data_extractor.select()
if __name__ == '__main__':
args = parser.parse_args()
main()