forked from matterport/Mask_RCNN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_db.py
executable file
·62 lines (51 loc) · 1.86 KB
/
create_db.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
52
53
54
55
56
57
58
59
60
61
62
import os
import sys
import shutil
from tqdm import tqdm
import time
def split_basename(basename):
base=basename
if basename.endswith(".txt"):
base=basename.rstrip(".txt")
elif basename.endswith(".png"):
base=basename.rstrip(".png")
splits=base.split("_")
vid,cam,id = "".join(splits[:-2]) , splits[-2], splits[-1]
return vid,cam,id
def parse_all_files(file):
files_dict={}
with open(file) as f:
for line in f:
line=line.rstrip("\n")
basename=os.path.basename(line)
vid,cam,id=split_basename(basename)
vid_frame = vid+"_"+id
if vid_frame in files_dict.keys():
files_dict[vid_frame].append(line)
else:
files_dict[vid_frame]=[line]
return files_dict
def get_file_list(batch_files, files_dict):
file_list=[]
for f in batch_files:
with open(f) as fin:
for line in fin:
line=line.rstrip("\n")
vid,cam,id=split_basename(line)
vid_frame = vid+"_"+id
if vid_frame in files_dict.keys():
file_list=file_list+files_dict[vid_frame]
else:
print("Something wrong with file "+vid)
return set(file_list)
def copy_in_output_folder(outfolder, img_selection):
for img in tqdm(img_selection):
shutil.copy(img, outfolder)
if __name__=="__main__":
batch_files=["batch1.txt","batch2.txt"] #list of filtered images (oyutput of check_objects)
all_files="images_ireland.txt" #list of ALL files
outfolder="/home/stephen/Pictures/output_irelandResults" #output
files=parse_all_files(all_files)
img_selection=get_file_list(batch_files, files)
#print(img_selection)
copy_in_output_folder(outfolder, img_selection)