-
Notifications
You must be signed in to change notification settings - Fork 23
/
showLabel.py
40 lines (35 loc) · 1.36 KB
/
showLabel.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
import cv2
import numpy as np
import os
import json
imgPath = "image"
images = os.listdir(imgPath)
config = os.listdir("config")
for im in images:
image = cv2.imread(imgPath+"/"+im)
print(im)
sp = im.split(".")[0].split("-")
for i in range(1, 6):
cfg = sp[0]+"-"+sp[1]+"_"+str(i)
if cfg+".json" in config:
print(cfg)
info = json.load(open("config/"+cfg+".json"))
x = info["ROI"]["x"]
y = info["ROI"]["y"]
w = info["ROI"]["w"]
h = info["ROI"]["h"]
cv2.rectangle(image, (x, y),
(x + w, y + h), (0, 0, 255), 5)
template = cv2.imread("template/"+cfg+".jpg")
start = np.array([info["startPoint"]["x"], info["startPoint"]["y"]])
end = np.array([info["endPoint"]["x"], info["endPoint"]["y"]])
center = np.array([info["centerPoint"]["x"], info["centerPoint"]["y"]])
cv2.circle(template, (start[0], start[1]), 20, (0, 0, 255), -1)
cv2.circle(template, (end[0], end[1]), 20, (0, 255, 0), -1)
cv2.circle(template, (center[0], center[1]), 20, (255, 0, 0), -1)
template = cv2.resize(template, (300, 300))
cv2.imshow(cfg, template)
image = cv2.resize(image, (300, 300))
cv2.imshow(im, image)
cv2.waitKey(0)
cv2.destroyAllWindows()