-
Notifications
You must be signed in to change notification settings - Fork 2
/
visualize.py
66 lines (52 loc) · 1.6 KB
/
visualize.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
56
57
58
59
60
61
62
63
64
65
66
# Visualize :
# read the detcted regions from the branch and bound output
# and Visualize the results using bounding boxes
# Author : Alaa El-Nouby
import cv2
import numpy as np
#path to video file
cap = cv2.VideoCapture('/home/alaaelnouby/Desktop/Branch and Bound/stip-2.0-linux/MSR Action Dataset/1.avi')
with open('/Branch&Bound binaries/cube.txt') as f:
content = f.readlines()
floats=[]
for i in range(int(len(content))):
f = [float(x) for x in content[i].split()]
floats.append(f)
arr = np.array(floats)
arr = arr.astype(np.float16)
x = arr[:, 0]
width = arr[:, 1]
y = arr[:, 2]
height = arr[:, 3]
t = arr[:, 4]
depth = arr[:, 5]
action = arr[:, 7]
print(arr)
time = 0
cv2.namedWindow('frame', flags=cv2.WINDOW_NORMAL)
while cap.isOpened():
ret, frame = cap.read()
# gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
for i in range(len(arr)):
if action[i] == 1:
color = (0, 0, 255)
text = "HandClapping"
elif action[i] == 2:
color = (0, 255, 0)
text = "HandWaving"
elif action[i] == 3:
color = (255, 0, 0)
text = "Boxing"
# print(time)
# print(t[i])
# print(depth[i])
# print("=================")
if time >= t[i] and time <= t[i]+depth[i]:
cv2.rectangle(frame, (x[i], y[i]), (x[i]+width[i], y[i]+height[i]), color)
cv2.putText(frame, text, (x[i], int(y[i]-5)), cv2.FONT_HERSHEY_SIMPLEX, 0.3, color, 1)
cv2.imshow('frame',frame)
if cv2.waitKey(40) & 0xFF == ord('q'):
break
time += 1
cap.release()
cv2.destroyAllWindows()