Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@elbruno
Created May 30, 2019 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbruno/b60b44b3bb945e046e7014d9fdb11bb4 to your computer and use it in GitHub Desktop.
Save elbruno/b60b44b3bb945e046e7014d9fdb11bb4 to your computer and use it in GitHub Desktop.
FaceDetectionFastDisplayPFS.py
# fast face detection sample with FPS in console
import face_recognition
import cv2
import time
video_capture = cv2.VideoCapture(0)
while True:
start_time = time.time()
ret, frame = video_capture.read()
fast_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
rgb_frame = fast_frame[:, :, ::-1]
face_locations = face_recognition.face_locations(rgb_frame)
for top, right, bottom, left in face_locations:
top *= 4
right *= 4
bottom *= 4
left *= 4
cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
cv2.imshow('Video', frame)
print("FPS: ", 1.0 / (time.time() - start_time)) # FPS = 1 / time to process loop
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment