I have low FPB ~5, I have checked this code on different cameras logitech c270 and logitech 9000, same situation.
I completed all the tips about turn off right light etc.
import urllib.request as urllib
import cv2
import numpy as np
import time
while True:
# Use urllib to get the image and convert into a cv2 usable format
cap = cv2.VideoCapture(0)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
hiegh = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
ret, frame = cap.read()
# put the image on screen
cv2.imshow('Webcam', frame)
if cv2.waitKey(1) & 0xFF == 27:
break
cap.release()
cv2.destroyAllWindows()
What should I do for increasing FPS ?
You need to move this line up, outside your acquisition loop:
cap = cv2.VideoCapture(0)
It does a one-time only initialisation.
I know I'm late but, if anyone else is facing this...
Check if you're using the right codec. In my case for a Logitech OrbiCam I had to set it to MJPG:
For C++:
cv::VideoCapture camera;
camera.open(0);
auto codec = cv::VideoWriter::fourcc('M','J','P','G');
camera.set(cv::CAP_PROP_FOURCC, codec);
In Python:
import cv2
camera = cv2.VideoCapture(0)
camera.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('m','j','p','g'))
For Kotlin:
var capture: VideoCapture = VideoCapture()
camera.open(deviceId)
val mjpg = VideoWriter.fourcc('M', 'J', 'P', 'G')
capture.set(Videoio.CAP_PROP_FOURCC, mjpg.toDouble())
etc...
...and then set your target resolution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With