I have a USB camera that is able to record 60 fps. I am using openCV with simple python code on Windows to capture some videos however it is not going all smoothly!
My main problem is that, if I set the [width, height]
properties to the maximum the camera accepts it is able to record 60 fps just fine otherwise (i.e. any lower resolution) the recording/streaming will drop to 30 fps max (the recording will be so funny that is either sped up or slowed down to match the specified recording fps; i.e. if the resolution specified 320X240 and recording fps set to 60 and for 10 seconds the resultant video will be squashed to 5 seconds so basically sped up 2x!!)
I don't understand why exactly that happens? any ideas?
here is a snippet of the code:
import cv2
import os
import time
def readVideo(Did):
cap = cv2.VideoCapture(Did)
# cap.set(cv2.CAP_PROP_FPS, 60) # no matter if you specify or not it selects what suits!!
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 320) # 640 is maximum
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240) # 480 is maximum
ret,frame = cap.read()
fourcc = cv2.VideoWriter_fourcc(*'XVID')
out = cv2.VideoWriter('./output.avi', fourcc, 60.0, (320,240)) # (width,height) must match what is stated above in CAP!
while ret:
ret,frame = cap.read()
elapsed = time.time() - start
count = count + 1 # frame numbers
cv2.putText(frame,str(cfpsBacked), (25,15),font,fontScale,fontColor,lineType)
out.write(frame)
cv2.imshow('camera',frame)
if elapsed - tick >= 1:
print("Actual count:{}",count)
tick += 1
cfpsBacked = count
count = 0
if tick - 10 == 0: # just records 10 seconds
break
if cv2.waitKey(10) & 0xFF == ord('q'):
break
out.release()
cap.release()
cv2.destroyAllWindows() # destroy all the opened windows