Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

facial expression recognition demo update (FPS added) #405

Merged
merged 6 commits into from
Feb 15, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from torchvision import transforms
import PIL
import cv2
import time

# OpenDR Modules
from opendr.perception.facial_expression_recognition import FacialEmotionLearner, image_processing
Expand Down Expand Up @@ -141,13 +142,23 @@ def webcam(learner, camera_id, display, frames):
"\nCheck whether a webcam is working or not.")

image_processing.set_fps(frames)

avg_fps = 0
try:
# Loop to process each frame from a VideoCapture object.
while image_processing.is_video_capture_open():
# Get a frame
img, _ = image_processing.get_frame()

start_time = time.perf_counter()

img = None if (img is None) else recognize_facial_expression(learner, img, display)

end_time = time.perf_counter()
fps = 1.0 / (end_time - start_time)
avg_fps = 0.8 * fps + 0.2 * fps
img = cv2.putText(img, "FPS: %.2f" % (avg_fps,), (10, 160), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2,
cv2.LINE_AA)

negarhdr marked this conversation as resolved.
Show resolved Hide resolved
if display and img is not None:
cv2.imshow('Result', img)
cv2.waitKey(1)
Expand Down