-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualize_output.py
executable file
·42 lines (32 loc) · 1.3 KB
/
visualize_output.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
# -*- coding: utf-8 -*-
#!/usr/bin/python3
# ****************************************************************************
# Copyright(c) 2017 Intel Corporation.
# License: MIT See LICENSE file in root directory.
# ****************************************************************************
# Utilities to help visualize the output from
# Intel® Movidius™ Neural Compute Stick (NCS)
import numpy
import PIL.Image
import PIL.ImageDraw
import PIL.ImageFont
def draw_bounding_box( y1, x1, y2, x2,
img,
thickness=4,
color=(255, 255, 0),
display_str=() ):
""" Inputs
(x1, y1) = Top left corner of the bounding box
(x2, y2) = Bottom right corner of the bounding box
img = Image/frame represented as numpy array
thickness = Thickness of the bounding box's outline
color = Color of the bounding box's outline
"""
img = PIL.Image.fromarray( img )
draw = PIL.ImageDraw.Draw( img )
for x in range( 0, thickness ):
draw.rectangle( [(x1-x, y1-x), (x2-x, y2-x)], outline=color )
font = PIL.ImageFont.load_default()
draw.text( (x1, y1), display_str, font=font )
return numpy.array( img )
# ==== End of file ===========================================================