Skip to content

Instantly share code, notes, and snippets.

@hewumars
Created March 5, 2019 08:36
Show Gist options
  • Save hewumars/0cb63204cfb53400680a07c3f0529cfb to your computer and use it in GitHub Desktop.
Save hewumars/0cb63204cfb53400680a07c3f0529cfb to your computer and use it in GitHub Desktop.
import os, sys
import argparse
def read_jpg_path_list(file_dir):
L=[]
fp = open(os.path.join(file_dir,'YoloTestSettrain.txt'),'w')
for root,dirs,files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == '.jpg':
L.append(os.path.join(root,file))
fp.write(os.path.join(root,file))
fp.write('\n')
fp.close()
return L
def main():
parser = argparse.ArgumentParser()
# Required arguments: input file.
parser.add_argument(
"--input_path",
help="Path to the input image"
)
# Optional arguments.
parser.add_argument(
"--output_file",
help="image path file."
)
args = parser.parse_args()
input_path = args.input_path
img_list = read_jpg_path_list(input_path)
output_file = 'window_file_voc2007_trainval.txt'
if args.output_file is not None:
output_file = args.output_file
fid = open(output_file, 'wt')
print len(img_list)
idCount = 0
for u in range(len(img_list)):
imgPath = img_list[u]
txtPath = img_list[u][:img_list[u].rfind('.jpg')]+'.txt'
rename_imgPath = imgPath[:imgPath.rfind('\\')+1] + 'hz_%07d.jpg'%(idCount)
rename_txtPath = txtPath[:txtPath.rfind('\\')+1] + 'hz_%07d.txt'%(idCount)
idCount += 1
os.rename(imgPath,rename_imgPath)
os.rename(txtPath,rename_txtPath)
print rename_imgPath
print rename_txtPath
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment