Skip to content

Commit aaf5d94

Browse files
committed
added helper function for showing text on frame
Signed-off-by: Mpho Mphego <mpho112@gmail.com>
1 parent c3ed3df commit aaf5d94

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ def main(args):
176176
predict_end_time, head_pose_angles = head_pose_estimation.predict(
177177
face, show_bbox=True
178178
)
179+
head_pose_estimation.show_text(frame, head_pose_angles)
179180
text = f"Head Pose Est. Inference time: {predict_end_time:.3f} s"
180181
head_pose_estimation.add_text(
181182
text, frame, (15, video_feed.source_height - 40)

src/model.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,25 @@ def draw_output(coords, image):
377377

378378
return image
379379

380+
@staticmethod
381+
def show_text(
382+
image, coords, pos=500, font_scale=1.5, color=(255, 255, 255), thickness=1
383+
):
384+
"""Helper function for showing the text on frame."""
385+
height, _ = image.shape[:2]
386+
ypos = abs(height - pos)
387+
text = ", ".join(f"{x}: {y:.2f}" for x, y in coords.items())
388+
389+
cv2.putText(
390+
image,
391+
text,
392+
(15, ypos),
393+
fontFace=cv2.FONT_HERSHEY_PLAIN,
394+
fontScale=font_scale,
395+
color=color,
396+
thickness=thickness,
397+
)
398+
380399

381400
class Gaze_Estimation(Base):
382401
"""Class for the Gaze Estimation Detection Model."""

0 commit comments

Comments
 (0)