Skip to content

Instantly share code, notes, and snippets.

@kuboshizuma
Last active March 17, 2020 02:55
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 kuboshizuma/213c5c9c68d7c8cb2d828dd86e2e85a7 to your computer and use it in GitHub Desktop.
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.
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