forked from alexmihalyk23/COCO2YOLO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
65 lines (59 loc) · 2.8 KB
/
test.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
65
import cv2
import time
import argparse
parser = argparse.ArgumentParser(description='Test yolo data.')
parser.add_argument('-i', help='Image', dest='img', required=True)
parser.add_argument('-t', help='Yolo text file', dest='txt',required=True)
args = parser.parse_args()
frame = cv2.imread(args.img)
cv2.namedWindow("f", cv2.WINDOW_NORMAL);
coordinates = []
with open(args.txt, "r") as lines:
for line in lines:
hT, wT, cT = frame.shape
coordinates = line.rstrip('\n').split(' ')
idx = coordinates[0]
x1, y1,w2,h2 = float(coordinates[1]), float(coordinates[2]), float(coordinates[3]), float(coordinates[4])
print(x1,y1,w2,h2)
w, h = int(w2 * wT), int(h2 * hT)
x, y = int((x1 * wT) - w / 2), int((y1 * hT) - h / 2)
# # 0 1 2 3 x1 - центр по x в процентах y1- центр по y в процентах w2- центр по w в процентах h2- центр по h в процентах
cv2.rectangle(frame, (x,y), (x+w, y+h), (0,255,255), 2)
cv2.putText(frame,str(idx), (x, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (128, 0, 255), 2)
cv2.imshow("f", frame)
cv2.waitKey(0)
# import cv2
# import time
# import argparse
# import numpy as np
# import matplotlib.pyplot as plt
# parser = argparse.ArgumentParser(description='Test yolo data.')
# parser.add_argument('-i', help='Image', dest='img', required=True)
# parser.add_argument('-t', help='Yolo text file', dest='txt',required=True)
# parser.add_argument('-l', help='labels txt file', dest='label',required=True)
# args = parser.parse_args()
# frame = cv2.imread(args.img)
# cv2.namedWindow("f", cv2.WINDOW_NORMAL);
# coordinates = []
# with open(args.txt, "r") as lines:
# for line in lines:
# hT, wT, cT = frame.shape
# coordinates = line.rstrip('\n').split(' ')
# idx = coordinates[0]
# x1, y1,w2,h2 = float(coordinates[1]), float(coordinates[2]), float(coordinates[3]), float(coordinates[4])
# print(x1,y1,w2,h2)
# cmap = plt.get_cmap('tab20b')
# colors = [cmap(i)[:3] for i in np.linspace(0, 1, 20)]
# color = colors[int(idx) % len(colors)]
# color = [i * 255 for i in color]
# w, h = int(w2 * wT), int(h2 * hT)
# x, y = int((x1 * wT) - w / 2), int((y1 * hT) - h / 2)
# with open(args.label, "r") as labels:
# classNames = labels.read().rstrip('\n').split('\n')
# # # 0 1 2 3 x1 - центр по x в процентах y1- центр по y в процентах w2- центр по w в процентах h2- центр по h в процентах
# cv2.rectangle(frame, (x,y), (x+w, y+h), color,3)
# print(len(classNames[1]))
# cv2.rectangle(frame, (x,y-30), (x+len(classNames[int(idx)]*15), y), color,-1)
# cv2.putText(frame,str(classNames[int(idx)]), (x+4, y-10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (255, 255, 255), 2)
# cv2.imshow("f", frame)
# cv2.waitKey(0)