-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·47 lines (37 loc) · 1.1 KB
/
main.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
#!/usr/bin/env python3
import json
import itertools
import cv2 as cv
from pathlib import Path
input_file = "RowlandF.json"
image_dir = "mvzip"
is_half = True
with open(input_file, "r") as f:
js = json.load(f)
bboxes = dict()
# Looks like the below, where images withou an annotation are None
# image_path (str): bbox[]
for image in js["images"]:
image_id = image["id"]
for annotation in js["annotations"]:
if annotation["image_id"] == image_id:
bboxes[image["file_name"]] = annotation["bbox"]
break
for i, (key, bbox) in enumerate(itertools.islice(bboxes.items(), 3, 33, 3)):
p = Path(image_dir) / input_file.split(".")[0] / key
image = cv.imread(str(p))
if is_half:
bbox = [int(b)//2 for b in bbox]
image = cv.resize(image, (image.shape[1]//2, image.shape[0]//2))
else:
bbox = [int(b) for b in bbox]
image = cv.rectangle(
image,
(bbox[0], bbox[1]),
(bbox[0] + bbox[2], bbox[1] + bbox[3]),
(0, 0, 255),
3,
)
cv.imshow(f"coyote{i}", image)
while cv.waitKey(0) != ord("q"):
pass