-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_info_column.py
110 lines (83 loc) · 3.42 KB
/
display_info_column.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import cv2
import numpy as np
import args
class DisplayInfoColumn:
def __init__(self,frame_height,left_margin=2,line_height = 20):
self.frame_height = frame_height
self.column_width = args.DISPLAY_COLUMN_WIDTH
self.left_margin = left_margin
self.line_height = line_height
self.age_gender_start = 20
self.colour_start = 230
def update_column_info(self,color_counts,age_gender_distribution):
# Function to update the black image with text
black_image = np.zeros((self.frame_height, self.column_width, 3), dtype=np.uint8)
# Text to be added to the black region
text = f"""
Age Gender Distribution (IN)
----------------------------------
Age Male Women
"""
for age_range, counts in age_gender_distribution.items():
text += f"{age_range:<10} {counts['Male']:<12} {counts['Female']:<12}\n"
# Split the text into lines and add them to the black region
lines = text.strip().split('\n')
y = self.age_gender_start # Vertical position to start adding text
for line in lines:
cv2.putText(black_image, line, (self.left_margin, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
y += self.line_height
text = f"""
Costum Colours
---------------------------------
Colour Upper Lower
"""
for color, counts in color_counts.items():
text += f"{color:<12} {counts['Upper Body']:<12} {counts['Lower Body']:<12}\n"
lines = text.strip().split('\n')
y = self.colour_start
for line in lines:
cv2.putText(black_image, line, (self.left_margin, y), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255, 255, 255), 1)
y += self.line_height
return black_image
if __name__ == '__main__':
video_path = 0
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
print("Error: Could not open video.")
exit()
frame_width = int(cap.get(3))
frame_height = int(cap.get(4))
color_counts = {
'Red': {'Upper Body': 2, 'Lower Body': 1},
'Blue': {'Upper Body': 0, 'Lower Body': 0},
'Green': {'Upper Body': 0, 'Lower Body': 0},
'White': {'Upper Body': 0, 'Lower Body': 0},
'Black': {'Upper Body': 0, 'Lower Body': 0},
'Yellow': {'Upper Body': 0, 'Lower Body': 0},
'Orange': {'Upper Body': 0, 'Lower Body': 0},
'Purple': {'Upper Body': 0, 'Lower Body': 0},
'Pink': {'Upper Body': 0, 'Lower Body': 0},
}
age_gender_distribution = {
"(4-6)": {"Male": 2, "Female": 3},
"(8-12)": {"Male": 0, "Female": 0},
"(15-20)": {"Male": 0, "Female": 0},
"(25-32)": {"Male": 0, "Female": 0},
"(38-43)": {"Male": 0, "Female": 0},
"(48-53)": {"Male": 0, "Female": 0},
"(60-100)": {"Male": 0, "Female": 0}
}
while True:
ret, frame = cap.read()
if not ret:
break
# Update the black image with current text values
display_column = DisplayInfoColumn(frame_height)
black_image = display_column.update_column_info(color_counts,age_gender_distribution)
# Concatenate the frame and black_image horizontally
combined_frame = np.hstack((frame, black_image))
cv2.imshow("LIVE",combined_frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
cv2.destroyAllWindows()