Last active
March 17, 2020 02:55
-
-
Save kuboshizuma/213c5c9c68d7c8cb2d828dd86e2e85a7 to your computer and use it in GitHub Desktop.
This script check whether your web camera successfully starts and how to work.
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
import time | |
import cv2 | |
import numpy as np | |
def webcam(): | |
video_capture = cv2.VideoCapture(0) | |
time_keep = time.time() | |
while True: | |
_, frame = video_capture.read() | |
fps = 1 / (time.time() - time_keep) | |
time_keep = time.time() | |
cv2.putText( | |
frame, | |
f'{fps:.2f} FPS', | |
(10, 30), | |
cv2.FONT_HERSHEY_SIMPLEX, | |
0.75, | |
(0, 255, 0), | |
thickness=1 | |
) | |
cv2.imshow('Res', frame) | |
# stop by 'q' command | |
if cv2.waitKey(1) & 0xFF == ord('q'): | |
break | |
video_capture.release() | |
cv2.destroyAllWindows() | |
if __name__ == '__main__': | |
webcam() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment