-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannotTransfer.py
64 lines (47 loc) · 2.09 KB
/
annotTransfer.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
63
64
import os
import pandas as pd
from pathlib import Path
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', None)
DAY_TRAIN_PATH = 'archive/Annotations/Annotations'
IMAGE_PATH = "archive/image"
IMAGEHEIGHT = 960
IMAGE_WIDTH = 1280
total_day_df = []
annotation = []
signal = ['go', 'warning', 'stop', 'goLeft', 'warningLeft', 'stopLeft']
dirList = os.listdir(IMAGE_PATH)
# create yolov5 annotation file for all image, there may have blank file for background image
for image in dirList:
an = open("annotation/" + os.path.splitext(image)[0] + ".txt", "w")
an.close()
for path in Path(DAY_TRAIN_PATH).iterdir():
for boxFile in path.rglob('frameAnnotationsBOX.csv'):
print(boxFile)
data = pd.read_csv(boxFile, sep=";")
file = data['Filename'].values
tag = data['Annotation tag'].values
ulX = data['Upper left corner X'].values
ulY = data['Upper left corner Y'].values
lrX = data['Lower right corner X'].values
lrY = data['Lower right corner Y'].values
if len(file) == len(tag) == len(ulX) == len(ulY) == len(lrX) == len(lrY):
for i, fileName in enumerate(file):
file[i] = os.path.split(fileName)[-1]
if file[i] in dirList:
wide = (lrX[i] - ulX[i]) / IMAGE_WIDTH
height = (lrY[i] - ulY[i]) / IMAGEHEIGHT
midX = (lrX[i] + ulX[i]) / 2 / IMAGE_WIDTH
midY = (ulY[i] + lrY[i]) / 2 / IMAGEHEIGHT
with open("annotation/"+os.path.splitext(file[i])[0]+".txt", "a") as annote:
if tag[i] in signal:
annote.write(str(signal.index(tag[i])) + " " + str(midX) + " " + str(midY) + " " + str(wide) + " " + str(height)+ "\n" )
else: print(tag[i])
# path = os.path.join(DAY_TRAIN_PATH, "frameAnnotationsBOX.csv")
# total_day_df.append(pd.read_csv(path, sep=";"))
# print(total_day_df)
# tdf_day = pd.concat(total_day_df)
# print(tdf_day)
# pd.