Skip to content

Commit 2bf2765

Browse files
Merge pull request #4 from Rits-Interaction-Laboratory/fix/show_fps_in_debug_mode
[Fix] DebugモードでもFPSが表示されるように修正
2 parents 0290ad1 + b96d236 commit 2bf2765

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

people_detection_ros2/people_detection_ros2/people_detection_node.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ def __init__(self):
7070

7171
def publish_from_img(self, img: np.ndarray, timestamp: Time):
7272
self.frame_count += 1
73+
if self.frame_count % self.measurement_count == 0:
74+
self.tm.stop()
75+
self.fps = (self.frame_count - self.before_frame) / self.tm.getTimeSec()
76+
self.before_frame = self.frame_count
77+
self.tm.reset()
78+
self.tm.start()
7379

7480
masked_img, boxes = self.people_detection_wrapper.detect(img)
7581

@@ -87,13 +93,6 @@ def publish_from_img(self, img: np.ndarray, timestamp: Time):
8793
if self.is_debug_mode:
8894
result_img = np.zeros(img.shape[:2]).astype(np.uint8)
8995

90-
if self.frame_count % self.measurement_count == 0:
91-
self.tm.stop()
92-
self.fps = (self.frame_count - self.before_frame) / self.tm.getTimeSec()
93-
self.before_frame = self.frame_count
94-
self.tm.reset()
95-
self.tm.start()
96-
9796
debug_img = cv2.cvtColor(result_img, cv2.COLOR_GRAY2BGR)
9897
cv2.putText(debug_img, "frame = " + str(self.frame_count), (0, 50), cv2.FONT_HERSHEY_PLAIN, 3, (0, 255, 0))
9998
cv2.putText(debug_img, 'FPS: {:.2f}'.format(self.fps),
@@ -109,7 +108,7 @@ def publish_from_img(self, img: np.ndarray, timestamp: Time):
109108
cv2.imshow('Result', cv2.hconcat([img, debug_img, combine_img]))
110109
cv2.waitKey(1)
111110

112-
print(f'[{datetime.datetime.now()}] fps : {self.fps}', end='\r')
111+
print(f'[{datetime.datetime.now()}] fps : {self.fps}', end='\r')
113112

114113
def get_img_callback(self, image_raw: Image) -> None:
115114
try:

0 commit comments

Comments
 (0)