-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImageShower.py
39 lines (35 loc) · 1.36 KB
/
ImageShower.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
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from VOC2012ImageReader import ImageReader
x = ImageReader.RESIZED_PIC_SIZE[0]
y = ImageReader.RESIZED_PIC_SIZE[1]
class ImageShower:
counter = 1
@staticmethod
def show_image_and_save(image, boxes, save=True):
fig, ax = plt.subplots()
print()
for i in range(len(boxes)):
for j in range(len(boxes[i])):
box = boxes[i][j]
if box[0] == 0:
continue
ax.add_patch(
patches.Rectangle(
((box[1] - box[3] / 2) * x, (box[2] - box[4] / 2) * y), # (x,y)
box[3] * x, # width
box[4] * y, # height
fill=False, color='red'))
plt.text(box[1] * x, (box[2] + box[4] / 2) * y + 10, ImageShower.__get_label(box), color='red')
ax.imshow(image)
plt.show()
if save:
fig.savefig('output' + str(ImageShower.counter) + ".png", format='png')
ImageShower.counter += 1
print(((box[1] - box[3] / 2) * x, (box[2] - box[4] / 2) * y, box[3] * x, box[4] * y))
@staticmethod
def __get_label(box):
for i in range(6, len(box)):
if box[i] == 1:
return ImageReader.CLASSES[i - 5]
return 'unknown'