Gabor Soter
Gabor Soter

Reputation: 61

OpenCV + OS X + external webcam = very slow

I'm using openCV on OS X with my external webcam (Microsoft Cinema HD Lifecam) and its performance is very low even with the simplest camera readout code.

import cv2
cap = cv2.VideoCapture(1)

while(cap.isOpened()):
    ret, frame = cap.read()
    cv2.imshow("Output", frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

I tried the same webcam with Photo Booth and it works well with high FPS. Also, I tried the same code with the built-in Facetime camera of my mac and it worked pretty fast. So, it seems like that I have some kind of configuration issue in OpenCV.

Has somebody ever experienced something like this? Thanks for your answers.

Upvotes: 2

Views: 2398

Answers (2)

Gabor Soter
Gabor Soter

Reputation: 61

It seems like I could solve my problem. I just had to decrease the resolution of the camera.

cap = cv2.VideoCapture(0)
cap.set(3,640)
cap.set(4,480)

I think Photo Booth sets the resolution automatically in order to increase the speed or the readout, however, one has to set this manually in OpenCV. Not sure about correctness of this explanation tough.

Upvotes: 4

ivan_onys
ivan_onys

Reputation: 2372

Try to enforce specific reader implementation, see here. Options to try CAP_QT and CAP_AVFOUNDATION, full list is here . Note, that OpenCV has to be built to support reader implementations.

Upvotes: 0

Related Questions