Luigi
commited on
Commit
·
846e714
1
Parent(s):
42892de
Internalize input frame buffer
Browse files- rtmo_demo.py +2 -6
- rtmo_gpu.py +5 -2
rtmo_demo.py
CHANGED
|
@@ -6,7 +6,6 @@ from pathlib import Path
|
|
| 6 |
import argparse
|
| 7 |
import os
|
| 8 |
from rtmo_gpu import RTMO_GPU_Batch, draw_skeleton, resize_to_fit_screen
|
| 9 |
-
from queue import Queue
|
| 10 |
|
| 11 |
if __name__ == "__main__":
|
| 12 |
|
|
@@ -28,18 +27,16 @@ if __name__ == "__main__":
|
|
| 28 |
|
| 29 |
# Now, use the best.url, which is the direct video link for streaming
|
| 30 |
cap = cv2.VideoCapture(filename=os.path.abspath(mp4_path))
|
| 31 |
-
in_queue = Queue(maxsize=args.batch_size)
|
| 32 |
frame_idx = 0
|
| 33 |
s = time.time()
|
| 34 |
while cap.isOpened():
|
| 35 |
success, frame = cap.read()
|
| 36 |
frame_idx += 1
|
| 37 |
-
in_queue.put(frame)
|
| 38 |
|
| 39 |
if not success:
|
| 40 |
break
|
| 41 |
|
| 42 |
-
keypoints, scores = body(frame)
|
| 43 |
|
| 44 |
if keypoints is not None:
|
| 45 |
if frame_idx % args.batch_size == 0 and frame_idx:
|
|
@@ -49,8 +46,7 @@ if __name__ == "__main__":
|
|
| 49 |
print(f'det: {fps} FPS')
|
| 50 |
s = current_time
|
| 51 |
|
| 52 |
-
|
| 53 |
-
img_show = frame.copy()
|
| 54 |
|
| 55 |
# if you want to use black background instead of original image,
|
| 56 |
# img_show = np.zeros(img_show.shape, dtype=np.uint8)
|
|
|
|
| 6 |
import argparse
|
| 7 |
import os
|
| 8 |
from rtmo_gpu import RTMO_GPU_Batch, draw_skeleton, resize_to_fit_screen
|
|
|
|
| 9 |
|
| 10 |
if __name__ == "__main__":
|
| 11 |
|
|
|
|
| 27 |
|
| 28 |
# Now, use the best.url, which is the direct video link for streaming
|
| 29 |
cap = cv2.VideoCapture(filename=os.path.abspath(mp4_path))
|
|
|
|
| 30 |
frame_idx = 0
|
| 31 |
s = time.time()
|
| 32 |
while cap.isOpened():
|
| 33 |
success, frame = cap.read()
|
| 34 |
frame_idx += 1
|
|
|
|
| 35 |
|
| 36 |
if not success:
|
| 37 |
break
|
| 38 |
|
| 39 |
+
frame_out, keypoints, scores = body(frame)
|
| 40 |
|
| 41 |
if keypoints is not None:
|
| 42 |
if frame_idx % args.batch_size == 0 and frame_idx:
|
|
|
|
| 46 |
print(f'det: {fps} FPS')
|
| 47 |
s = current_time
|
| 48 |
|
| 49 |
+
img_show = frame_out.copy()
|
|
|
|
| 50 |
|
| 51 |
# if you want to use black background instead of original image,
|
| 52 |
# img_show = np.zeros(img_show.shape, dtype=np.uint8)
|
rtmo_gpu.py
CHANGED
|
@@ -579,6 +579,7 @@ class RTMO_GPU_Batch(RTMO_GPU):
|
|
| 579 |
|
| 580 |
def __call__(self, image: np.array):
|
| 581 |
self.buffer.append(image)
|
|
|
|
| 582 |
|
| 583 |
if len(self.buffer) == self.batch_size:
|
| 584 |
b_keypoints, b_scores = self.__batch_call__(self.buffer)
|
|
@@ -586,11 +587,12 @@ class RTMO_GPU_Batch(RTMO_GPU):
|
|
| 586 |
self.out_queue.put((keypoints, scores))
|
| 587 |
self.buffer = []
|
| 588 |
|
| 589 |
-
keypoints, scores = None, None
|
| 590 |
if not self.out_queue.empty():
|
| 591 |
keypoints, scores = self.out_queue.get()
|
|
|
|
| 592 |
|
| 593 |
-
return keypoints, scores
|
| 594 |
|
| 595 |
|
| 596 |
def __init__(self,
|
|
@@ -607,6 +609,7 @@ class RTMO_GPU_Batch(RTMO_GPU):
|
|
| 607 |
is_yolo_nas_pose)
|
| 608 |
|
| 609 |
self.batch_size = batch_size
|
|
|
|
| 610 |
self.out_queue = Queue(maxsize=self.batch_size)
|
| 611 |
self.buffer = []
|
| 612 |
|
|
|
|
| 579 |
|
| 580 |
def __call__(self, image: np.array):
|
| 581 |
self.buffer.append(image)
|
| 582 |
+
self.in_queue.put(image)
|
| 583 |
|
| 584 |
if len(self.buffer) == self.batch_size:
|
| 585 |
b_keypoints, b_scores = self.__batch_call__(self.buffer)
|
|
|
|
| 587 |
self.out_queue.put((keypoints, scores))
|
| 588 |
self.buffer = []
|
| 589 |
|
| 590 |
+
frame, keypoints, scores = None, None, None
|
| 591 |
if not self.out_queue.empty():
|
| 592 |
keypoints, scores = self.out_queue.get()
|
| 593 |
+
frame = self.in_queue.get()
|
| 594 |
|
| 595 |
+
return frame, keypoints, scores
|
| 596 |
|
| 597 |
|
| 598 |
def __init__(self,
|
|
|
|
| 609 |
is_yolo_nas_pose)
|
| 610 |
|
| 611 |
self.batch_size = batch_size
|
| 612 |
+
self.in_queue = Queue(maxsize=self.batch_size)
|
| 613 |
self.out_queue = Queue(maxsize=self.batch_size)
|
| 614 |
self.buffer = []
|
| 615 |
|