Why is Python OpenCV camera read in Ubuntu slower than Windows?
Question:
I have a really simple code to view video from web-cam (Microsoft HD LifeCam Studio) as follow:
import cv2
from imutils.video import FPS
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
fps = FPS().start()
while cap.isOpened():
_,frame = cap.read()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
fps.update()
fps.stop()
print("{}".format(fps.fps()))
cap.release()
cv2.destroyAllWindows()
The code will print out the FPS when the program ends.
When running this code on Windows, I receive 30 FPS. However, when running on Ubuntu, I only receive 10 FPS.
I have tried cap.set(cv2.cv.CV_CAP_PROP_FPS, 30)
but it does not work.
Does anyone experience the same situation? Is there any solution for this problem?
I’m running Windows 10 and Ubuntu 16.04
Python 3.5.2
OpenCV 3.4.0
Answers:
The problem lies on how I install the OpenCV framework. In Ubuntu, I use pip
to install the OpenCV which causes the weak performance. Instead of using pip
, I built OpenCV from the source code which enhance the performance to the same as in Windows.
I have a really simple code to view video from web-cam (Microsoft HD LifeCam Studio) as follow:
import cv2
from imutils.video import FPS
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
fps = FPS().start()
while cap.isOpened():
_,frame = cap.read()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
fps.update()
fps.stop()
print("{}".format(fps.fps()))
cap.release()
cv2.destroyAllWindows()
The code will print out the FPS when the program ends.
When running this code on Windows, I receive 30 FPS. However, when running on Ubuntu, I only receive 10 FPS.
I have tried cap.set(cv2.cv.CV_CAP_PROP_FPS, 30)
but it does not work.
Does anyone experience the same situation? Is there any solution for this problem?
I’m running Windows 10 and Ubuntu 16.04
Python 3.5.2
OpenCV 3.4.0
The problem lies on how I install the OpenCV framework. In Ubuntu, I use pip
to install the OpenCV which causes the weak performance. Instead of using pip
, I built OpenCV from the source code which enhance the performance to the same as in Windows.