Skip to content

Instantly share code, notes, and snippets.

@rajathithan
Created May 7, 2020 19:58
Show Gist options
  • Save rajathithan/1a4f663ce70adf015798491594b37c69 to your computer and use it in GitHub Desktop.
Save rajathithan/1a4f663ce70adf015798491594b37c69 to your computer and use it in GitHub Desktop.
webcamfeed.py
import cv2
import imutils
cap = cv2.VideoCapture(0)
t = cv2.getTickCount()
count = 0
fps = 60.0
while(True):
if count==0:
t = cv2.getTickCount()
# Read the frame
ret, frame = cap.read()
#Resize the frame
frame = imutils.resize(frame, width = 640)
frame = imutils.resize(frame, height = 480)
# increment frame counter
count = count + 1
# calculate fps at an interval of 100 frames
if (count == 100):
t = (cv2.getTickCount() - t)/cv2.getTickFrequency()
fps = 100.0/t
count = 0
# Get frame size
size = frame.shape[0:2]
cv2.putText(frame, "{0:.2f}-fps".format(fps), (50, size[0]-50), cv2.FONT_HERSHEY_COMPLEX, 1.5, (0, 0, 255), 3)
# Display the resulting frame
winname = 'Read Webcam Feed'
cv2.imshow(winname,frame)
#Waits for a user input to quit the application
key = cv2.waitKey(10)
mouse = cv2.getWindowProperty(winname,cv2.WND_PROP_VISIBLE)
if key == 27 or mouse < 1:
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment