OpenCV 2.1: Integration video capture into wxPython

imo Python is going to be too slow for frame-by-frame capture with open-cv.

Have you thought about having the video loop in c and sending a message
in python to the C loop when you need to pick up a frame?

I’m working in OpenCV using python.multiprocessing but I am doing
all the video handling in C++. The C++ code sends messages to the python
code in a message bus on tcp/ip when it finds information in the images.

The ‘brain’ is in python…

Then I have a ‘dumb’ wxpython display, also connected to the tcp/ip
bus which picks up information and displays it to the user.

http://bitbucket.org/djlyon/smp-driverless-car-robot/src

···

On Sat, Nov 27, 2010 at 9:31 AM, Convoluted xenon2k8@gmail.com wrote:

Hello all. I would like to integrate a live video stream from an

attached video device (webcam, USB capture, etc) into a panel in a

wxPython GUI. I initially found sample code from the folks at OpenCV

(http://opencv.willowgarage.com/wiki/wxpython) but it seems to be

older versions of OpenCV, namely version 1.x. I have attempted to

convert this code for OpenCV 2.1 but I’m having difficulties getting

the GUI to execute. I’m not sure what exactly the problem is, but I

suspect that there might be a few more changes from 1.x to 2.1 other

than just syntax. Does anyone have any experience with OpenCV 2.1 +

wxPython? I would be grateful for any suggestions. Here is my attempt

to far:

import wx

import sys

import cv

sys.path.append(‘C:\OpenCV2.1\Python2.6\Lib\site-packages’)

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)

    #dst = cv.CreateImage(cv.GetSize(capturedImage),

cv.IPL_DEPTH_16S, 3) # NEED THIS?

    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)

    self.Show(True)

    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)

    evt.Skip()



def onNextFrame(self, evt):

    capturedImage = cv.QueryFrame(self.capture)

    if capturedImage:

        cv.CvtColor(capturedImage, capturedImageModified,

cv.CV_BGR2RGB)

self.buildBmp.CopyFromBuffer(capturedImageModified.tostring())

        self.Refresh()

    evt.Skip()

if name==“main”:

app = wx.App()

app.RestoreStdio()

captureTest(None)

app.MainLoop()

To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en