Using python OpenCV binding to display webcam stream in PySide widgets

Hey, if anyone can help me that would be great. I am trying to use OpenCV to take a webcam stream and then display it in a PySide app by updating the image.

cv.NamedWindow('Raw', cv.CV_WINDOW_AUTOSIZE)
self.cap = cv.CaptureFromCAM(0)

      

This works and I am updating the named window in a while loop with show image function.

while True:
    frame = cv.QueryFrame(self.cap)
    img = cv.CreateImage(cv.GetSize(frame),cv.IPL_DEPTH_8U,1)
    if frame is None:
        print "Frame is none"
        sys.exit(1)
    # display webcam image
    cv.ShowImage('Raw', frame)

      

But when I try to display images in a PySide application, I just see a blank black image (The following code is in the same while loop as above)

image = QImage(frame.tostring(), frame.width, frame.height, QImage.Format_RGB888).rgbSwapped()
self.pixmap = QPixmap.fromImage(image)
grid = QGridLayout()
grid.setSpacing(10)
imageBox = QLabel(self)
imageBox.setGeometry(0,0,300,200)
imageBox.setPixmap(self.pixmap.scaled(300,200))
grid.addWidget(imageBox)
self.widget.setLayout(grid)
self.repaint()            

      

Does anyone know why the image is not updating?

+3


source to share





All Articles