forked from goktug97/TargetPersonTracker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
executable file
·55 lines (46 loc) · 1.64 KB
/
utils.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
#!/usr/bin/env python
"""Common functions for other modules."""
import cv2
import numpy as np
colors = np.array([[0.0, 0.0, 127.0],
[0.0, 0.0, 204.0],
[0.0, 89.0, 255.0],
[0.0, 204.0, 255.0],
[77.0, 255.0, 153.0],
[153.0, 255.0, 77.0],
[255.0, 230.0, 0.0],
[255.0, 126.0, 0.0],
[255.0, 26.0, 0.0],
[123.0, 0.0, 0.0]])
def draw_str(dst, target, s):
"""Draw cool string on image."""
"""Taken from opencv samples"""
x, y = target
cv2.putText(dst, s, (x+1, y+1),
cv2.FONT_HERSHEY_PLAIN, 1.0,
(0, 0, 0), thickness=2,
lineType=cv2.LINE_AA)
cv2.putText(dst, s, (x, y),
cv2.FONT_HERSHEY_PLAIN, 1.0,
(255, 255, 255),
lineType=cv2.LINE_AA)
def nms(rects, overlapThresh=0.65):
from imutils.object_detection import non_max_suppression
"""Do non-max supression on detections."""
picks = non_max_suppression(rects,
probs=None,
overlapThresh=overlapThresh)
return picks
def draw_detections(frame, dets):
"""Draws rectangles to given frame."""
"""
Draw rectangles directly on given input,
doesn't create a copy.
dets = xmin, ymin, xmax, ymax
"""
if len(dets) > 0 and dets[0] is not None:
for det in dets:
xmin, ymin, xmax, ymax = det
cv2.rectangle(frame, (xmin, ymin),
(xmax, ymax),
(255, 255, 255), 3)