Webcam access from pyside / opencv

I have problems accessing the webcam in the pyside / opencv project.

This is a stripped-down example that causes the problem I am facing:

from PySide import QtCore, QtGui
import cv, cv2, time, ImageQt

app = QtGui.QApplication([])

while True:
    camcapture = cv.CaptureFromCAM(0)
    cv.SetCaptureProperty(camcapture,cv.CV_CAP_PROP_FRAME_WIDTH, 1280)
    cv.SetCaptureProperty(camcapture,cv.CV_CAP_PROP_FRAME_HEIGHT, 720);

    frame = cv.QueryFrame(camcapture)
    image = QtGui.QImage(frame.tostring(), frame.width, frame.height, QtGui.QImage.Format_RGB888).rgbSwapped()
    pixmap = QtGui.QPixmap.fromImage(image)

app.exec_()

Here I see two problems. First: I see a problem using v4l2 to access the webcam, which otherwise works fine with python (using other applications):

python ./test.py 
VIDIOC_QUERYMENU: Invalid argument
[... and countless more entries which don#t worry me ...]
VIDIOC_QUERYMENU: Invalid argument
libv4l2: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl S_FMT
libv4l2: error setting pixformat: Device or resource busy
libv4l1: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl VIDIOCSPICT

Then there is a problem with closing that is unclear, but not my main problem right now:

*** glibc detected *** python: double free or corruption (fasttop): 0x00000000029368f0 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x78b66)[0x7f3539f06b66]
/usr/lib64/tls/libnvidia-tls.so.304.64(+0x1cc1)[0x7f352e448cc1]
======= Memory map: ========
00400000-00401000 r-xp 00000000 08:02 3937950                            /usr/bin/python2.7
00600000-00601000 r--p 00000000 08:02 3937950                            /usr/bin/python2.7
00601000-00602000 rw-p 00001000 08:02 3937950                            /usr/bin/python2.7
01631000-03cd3000 rw-p 00000000 00:00 0                                  [heap]
7f351b6dc000-7f351b6dd000 rw-p 00000000 00:00 0 
7f351b6dd000-7f351b773000 rw-s 001c2000 00:05 5759                       /dev/video0
7f351b773000-7f351b809000 rw-s 0012c000 00:05 5759                       /dev/video0
[... and so on ... and so on ... ]

My question I do not understand the meaning of the output. I tried many variations of the code, but usually came up with the same problem. Therefore, I assume that this is not a specific part of the code, but some general problem with my setup or my approach. This is the environment: - Linux OS (openSUSE-12.2) on x86-64 platform (MacBook Pro) - opencv 2.4.3 - libqt4 4.8.4 - python 2.7.3

? . ?

+1
1

cv.CaptureFromCAM(0) while, " " .

, , while. cv2.waitKey() time.sleep().

Qt. (, -, .)

:

import cv, cv2, time, sys

camcapture = 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)

cv2:

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

All Articles