Skip to content

Instantly share code, notes, and snippets.

@toandaominh1997
Created December 7, 2019 04:15
Show Gist options
  • Save toandaominh1997/c914717c91dd6dbd07b45058bd1b1aac to your computer and use it in GitHub Desktop.
Save toandaominh1997/c914717c91dd6dbd07b45058bd1b1aac to your computer and use it in GitHub Desktop.
import cv2
cap = cv2.VideoCapture()
# cap.open(2, apiPreference=cv2.CAP_V4L2)
cap.open(2)
cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)
cap.set(cv2.CAP_PROP_FPS, 30.0)
import time
num_frame = 0
start = time.time()
while(True):
ret, frame = cap.read()
num_frame +=1
if(num_frame%100==0):
print('FPS: ', 100/(time.time()-start))
start = time.time()
cv2.imshow('Frame', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
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