Hello all. I'm trying to get a video feed in a wxPython GUI (under MS Windows) and thought about using OpenCV. There is a short tutorial on how to achieve this at this page: http://opencv.willowgarage.com/wiki/wxpython (updated late 2009). The problem I'm having is trying to load the libraries to get it to work. I downloaded the exe version of 2.1, which when installed creates the directory "C:\OpenCV2.1", and inside is a folder "bin" with a bunch of DLLs. I assume since there are DLLs in this version I don't need to build or compile any files?

I then tried moving the DLLs to Python's lib\site-packages folder and then tried import the libraries need for the code, but I get the error:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import opencv.cv as cv
ImportError: No module named opencv.cv

and

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import opencv.highgui as gui
ImportError: No module named opencv.highgui

Strangely, according to the OpenCV Pythondocumentation (http://opencv.willowgarage.com/documentation/python/introduction.html), there is now a single import of all of OpenCV using import cv and OpenCV functions no longer have the "cv" prefix. Could this potentially be the issue? Either way, not exactly sure where I'm going wrong. It's obvious I'm missing some key piece of information, and any help would be as always much appreciated. Here's the code I'm trying to get working (taken from the link above).

import wx
import opencv.cv as cv
import opencv.highgui as gui

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

        self.capture = gui.cvCreateCameraCapture(-1)
        frame = gui.cvQueryFrame(self.capture)
        self.SetSize((frame.width, frame.height))
        self.displayPanel = wx.Panel(self, -1)
        cv.cvCvtColor(frame, frame, cv.CV_BGR2RGB)
        self.bmp = wx.BitmapFromBuffer(frame.width, frame.height, frame.imageData)
        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.bmp:
            dc=wx.BufferedPaintDC(self.displayPanel, self.bmp)
        evt.Skip()

    def onNextFrame(self, evt):
        frame = gui.cvQueryFrame(self.capture)
        if frame:
            cv.cvCvtColor(frame, frame, cv.CV_BGR2RGB)
            self.bmp.CopyFromBuffer(frame.imageData)
            self.Refresh()
        evt.Skip()

if __name__=="__main__":
    app = wx.App()
    app.RestoreStdio()
    CvMovieFrame(None)
    app.MainLoop()

Ok think I may have found out some key info. What I read is true, import opencv.cv as cv and import opencv.highgui as gui do not exist in OpenCV 2.x. If I installed OpenCV 1.x it works fine. The question now is whether to convert the code to be usable in 2.x or to just keep using 1.x.

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.