@@ -33,6 +33,7 @@ def _draw_frame(self, frame: ma.MaskedArray, frame_confidence: np.ndarray, img)
33
33
34
34
for person , person_confidence in zip (frame , frame_confidence ):
35
35
c = person_confidence .tolist ()
36
+ points_2d = [tuple (p ) for p in person [:, :2 ].tolist ()]
36
37
idx = 0
37
38
for component in self .pose .header .components :
38
39
colors = [np .array (c [::- 1 ]) for c in component .colors ]
@@ -50,42 +51,33 @@ def _point_color(p_i: int):
50
51
color = _point_color (i ), thickness = - 1 , lineType = 16 )
51
52
52
53
if self .pose .header .is_bbox :
53
- point1 = tuple ( person [0 + idx ]. tolist ())
54
- point2 = tuple ( person [1 + idx ]. tolist ())
54
+ point1 = points_2d [0 + idx ]
55
+ point2 = points_2d [1 + idx ]
55
56
color = tuple (np .mean ([_point_color (0 ), _point_color (1 )], axis = 0 ))
56
57
57
58
self .cv2 .rectangle (img = img , pt1 = point1 , pt2 = point2 , color = color , thickness = thickness )
58
59
else :
59
- int_person = person .astype (np .int32 )
60
60
# Draw Limbs
61
61
for (p1 , p2 ) in component .limbs :
62
62
if c [p1 + idx ] > 0 and c [p2 + idx ] > 0 :
63
- point1 = tuple ( int_person [p1 + idx ]. tolist ()[: 2 ])
64
- point2 = tuple ( int_person [p2 + idx ]. tolist ()[: 2 ])
63
+ point1 = points_2d [p1 + idx ]
64
+ point2 = points_2d [p2 + idx ]
65
65
66
66
# length = ((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2) ** 0.5
67
67
68
68
color = tuple (np .mean ([_point_color (p1 ), _point_color (p2 )], axis = 0 ))
69
69
70
70
self .cv2 .line (img , point1 , point2 , color , thickness , lineType = self .cv2 .LINE_AA )
71
71
72
- # deg = math.degrees(math.atan2(point1[1] - point2[1], point1[0] - point2[0]))
73
- # polygon = cv2.ellipse2Poly(
74
- # (int((point1[0] + point2[0]) / 2), int((point1[1] + point2[1]) / 2)),
75
- # (int(length / 2), thickness),
76
- # int(deg),
77
- # 0, 360, 1)
78
- # cv2.fillConvexPoly(img=img, points=polygon, color=color)
79
-
80
72
idx += len (component .points )
81
73
82
74
return img
83
75
84
76
def draw (self , background_color : Tuple [int , int , int ] = (255 , 255 , 255 ), max_frames : int = None ):
85
- int_data = np .array (np .around (self .pose .body .data .data ), dtype = "int32" )
77
+ int_frames = np .array (np .around (self .pose .body .data .data ), dtype = "int32" )
86
78
background = np .full ((self .pose .header .dimensions .height , self .pose .header .dimensions .width , 3 ),
87
79
fill_value = background_color , dtype = "uint8" )
88
- for frame , confidence in itertools .islice (zip (int_data , self .pose .body .confidence ), max_frames ):
80
+ for frame , confidence in itertools .islice (zip (int_frames , self .pose .body .confidence ), max_frames ):
89
81
yield self ._draw_frame (frame , confidence , img = background .copy ())
90
82
91
83
def draw_on_video (self , background_video , max_frames : int = None , blur = False ):
@@ -162,3 +154,34 @@ def save_video(self, f_name: str, frames: Iterable[np.ndarray], custom_ffmpeg=No
162
154
out .write (frame )
163
155
164
156
out .close ()
157
+
158
+
159
+ class FastAndUglyPoseVisualizer (PoseVisualizer ):
160
+ """
161
+ This class draws all frames as grayscale, without opacity based on confidence
162
+ """
163
+
164
+ def _draw_frame (self , frame : ma .MaskedArray , img , color : int ):
165
+ ignored_point = (0 , 0 )
166
+ # Note: this can be made faster by drawing polylines instead of lines
167
+ thickness = 1
168
+ for person in frame :
169
+ points_2d = [tuple (p ) for p in person [:, :2 ].tolist ()]
170
+ idx = 0
171
+ for component in self .pose .header .components :
172
+ for (p1 , p2 ) in component .limbs :
173
+ point1 = points_2d [p1 + idx ]
174
+ point2 = points_2d [p2 + idx ]
175
+ if point1 != ignored_point and point2 != ignored_point :
176
+ # Antialiasing is a bit slow, but necessary
177
+ self .cv2 .line (img , point1 , point2 , color , thickness , lineType = self .cv2 .LINE_AA )
178
+
179
+ idx += len (component .points )
180
+ return img
181
+
182
+ def draw (self , background_color : int = 0 , foreground_color : int = 255 ):
183
+ int_frames = np .array (np .around (self .pose .body .data .data ), dtype = "int32" )
184
+ background = np .full ((self .pose .header .dimensions .height , self .pose .header .dimensions .width ),
185
+ fill_value = background_color , dtype = "uint8" )
186
+ for frame in int_frames :
187
+ yield self ._draw_frame (frame , img = background .copy (), color = foreground_color )
0 commit comments