Skip to content Skip to sidebar Skip to footer

Accessing A Webcam From Pyside / Opencv

I have problems accessing a webcam in a pyside / opencv project. This is a stripped down example that produces the problem I face: from PySide import QtCore, QtGui import cv, cv2

Solution 1:

To start with, you should not have cv.CaptureFromCAM(0) inside the while loop, as that is what is causing the "resource busy" collisions and the memory dump.

You will likely need to slow down your while loop. You can implement cv2.waitKey() or use time.sleep().

After that, you will need to finish your Qt implementation. (which seems to be a separate issue.)

Here is a bare bones re-write of your example:

import cv, cv2, time, syscamcapture= cv.CaptureFromCAM(0)
cv.SetCaptureProperty(camcapture,cv.CV_CAP_PROP_FRAME_WIDTH, 1280)
cv.SetCaptureProperty(camcapture,cv.CV_CAP_PROP_FRAME_HEIGHT, 720)

while True:
    frame = cv.QueryFrame(camcapture)
    ... GUI stuff ...
    time.sleep(.05)

Using cv2 instead:

camcapture = cv2.VideoCapture(0)
while True:
    _, frame = camcapture.read()
    ... GUI stuff ...
    time.sleep(.05)

Post a Comment for "Accessing A Webcam From Pyside / Opencv"