Skip to content

Instantly share code, notes, and snippets.

@elbruno
Created September 25, 2019 11:42
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/8d64daca43a14028385f9e3c1d1babaa to your computer and use it in GitHub Desktop.
Save elbruno/8d64daca43a14028385f9e3c1d1babaa to your computer and use it in GitHub Desktop.
PythonWebCamFeed.py
import os
import cv2
import time
# init camera
execution_path = os.getcwd()
camera = cv2.VideoCapture(0)
while True:
# Init and FPS process
start_time = time.time()
# Grab a single frame of video
ret, frame = camera.read()
# calculate FPS >> FPS = 1 / time to process loop
fpsInfo = "FPS: " + str(1.0 / (time.time() - start_time))
print(fpsInfo)
cv2.putText(frame, fpsInfo, (10, 10), cv2.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1)
# Display the resulting image
cv2.imshow('Video', frame)
# Hit 'q' on the keyboard to quit!
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release handle to the webcam
camera.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment