-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoc_annotation.py
30 lines (28 loc) · 980 Bytes
/
voc_annotation.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
import os
import random
import xml.etree.ElementTree as ET
import numpy as np
import glob
import os
sets = ['train', 'val']
if __name__ == "__main__":
base_dir = "dataset"
for set in sets:
with open(set + ".txt", 'w', encoding="utf-8") as f:
path = base_dir + os.sep + set
print(path)
num_img = glob.glob(path + os.sep + "*.jpg")
# 遍历所有文件
for img in num_img:
f.write(img)
file_path = img.replace("jpg", "txt")
readlines = open(file_path, 'r', encoding="utf-8")
lines = [line.strip() for line in readlines.readlines()]
for line in lines:
line = line.replace('(', "")
line = line.replace(')', "")
line = line.replace(' ', "")
f.write(" " + line)
f.write("\n")
readlines.close()
f.close()