Created
June 27, 2019 17:26
-
-
Save elbruno/2c6cb480fb38e3c6254ae9f46b960098 to your computer and use it in GitHub Desktop.
FaceDetectionOpenCvOpenCameraLowResolution.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# standard face detection sample with FPS in console | |
# open camera in low resolution to get better FPS | |
import face_recognition | |
import cv2 | |
import time | |
video_capture = cv2.VideoCapture(0) | |
video_capture.set(cv2.CAP_PROP_FRAME_WIDTH,640) | |
video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT,480) | |
while True: | |
start_time = time.time() | |
ret, frame = video_capture.read() | |
rgb_frame = frame[:, :, ::-1] | |
face_locations = face_recognition.face_locations(rgb_frame) | |
for top, right, bottom, left in face_locations: | |
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