-
Notifications
You must be signed in to change notification settings - Fork 16
/
create_filelist.py
29 lines (25 loc) · 1.11 KB
/
create_filelist.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
import argparse
import os
import glob
parser = argparse.ArgumentParser()
requiredArguments = parser.add_argument_group("required arguments")
requiredArguments.add_argument("-d", "--dir", type=str, required=True, help="Directory containing the annotations/images")
requiredArguments.add_argument("-o", "--outfile", type=str, required=True, help="File containing the absolute path to the images")
args = parser.parse_args()
imgs = []
imgExts = [".jpg", ".jpeg", ".png"]
for root, directories, filenames in os.walk(args.dir):
for filename in filenames:
basename = os.path.basename(filename)
split = os.path.splitext(basename)
if(len(split) > 1):
if split[1].lower() in imgExts:
path = os.path.join(root, filename);
imgs.append(os.path.abspath(path))
with open(args.outfile, 'w') as outFile:
for img in imgs:
parent = os.path.abspath(os.path.join(img, os.pardir))
imgbase = os.path.splitext(os.path.basename(img))[0]
annFile = os.path.join(parent, imgbase+".txt")
if(os.path.isfile(annFile)):
outFile.write(img+"\n")