Hi all. I'm trying to capture video from a webcam and then display the feed in a wxPython GUI. I originally borrowed code from the OpenCV wiki (http://opencv.willowgarage.com/wiki/wxpython), and since the code was for OpenCV 1.x I tried to adapt it for version 2.1. Here's my attempt to far:

import wx
import sys
import cv


class captureTest(wx.Frame):
    TIMER_PLAY_ID = 101
    def __init__(self, parent):
        wx.Frame.__init__(self, parent, -1)

        self.capture = cv.CaptureFromCAM(0)
        capturedImage = cv.QueryFrame(self.capture)
        self.SetSize((capturedImage.width, capturedImage.height))
        self.displayPanel = wx.Panel(self, -1)
        cv.CvtColor(capturedImage, capturedImageModified, cv.CV_BGR2RGB)
        self.buildBmp = wx.BitmapFromBuffer(capturedImageModified.width, capturedImageModified.height, capturedImageModified.tostring())
        self.Bind(wx.EVT_PAINT, self.onPaint)

        self.playTimer = wx.Timer(self, self.TIMER_PLAY_ID)
        wx.EVT_TIMER(self, self.TIMER_PLAY_ID, self.onNextFrame)
        fps = gui.cvGetCaptureProperty(self.capture, gui.CV_CAP_PROP_FPS)

        if fps!=0: self.playTimer.Start(1000/fps) #every X ms
        else: self.playTimer.Start(1000/15) #assuming 15 fps

    def onPaint(self, evt):
        if self.buildBmp:
            dc=wx.BufferedPaintDC(self.displayPanel, self.buildBmp)

    def onNextFrame(self, evt):
        capturedImage = cv.QueryFrame(self.capture)
        if capturedImage:
            cv.CvtColor(capturedImage, capturedImageModified, cv.CV_BGR2RGB)

if __name__=="__main__":
    app = wx.App()

I'm having issues getting the GUI to launch. Either there's issues will null pointers or some other sort of error. I feel like I'm forgetting something trivial. Any ideas?

capturedImageModified is never initialized (at least according to Python).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.