Question about image from webcame in opencv

asked 2016-01-26 03:17:07 -0500

updated 2016-04-19 03:59:48 -0500

Hello everybody.

I have read all three or four current threads on this subject that are on the internet, and so far none accurately answer the question.

I am fairly new to wxPython, although I have some experience with FLTK. I am new to OpenCV.

I am attempting to capture an image from a webcam with openCV and paint that image into wxPython. I have had limited success (I can get an image and paint it, but it's faint and not aligned properly). I can confirm that my webcam and openCV are working on their own, because sample code like this works as expected.

Here is an example of my latest effort, which I've cobbled together from the internet and my own efforts with opencv2.

import wx
import cv2

class viewWindow(wx.Frame):
    imgSizer = (480,360)
    def __init__(self, parent, title="View Window"):
            super(viewWindow,self).__init__(parent)
            self.pnl = wx.Panel(self)
            self.vbox = wx.BoxSizer(wx.VERTICAL)
            self.image = wx.EmptyImage(self.imgSizer[0],self.imgSizer[1])
            self.imageBit = wx.BitmapFromImage(self.image)
            self.staticBit = wx.StaticBitmap(self.pnl,wx.ID_ANY,
                self.imageBit)
            self.vbox.Add(self.staticBit)
            self.pnl.SetSizer(self.vbox)
            self.timex = wx.Timer(self, wx.ID_OK)
            self.timex.Start(1000/12)
            self.Bind(wx.EVT_TIMER, self.redraw, self.timex)
            self.capture = cv2.VideoCapture(0)
            self.SetSize(self.imgSizer)
            self.Show()
    def redraw(self,e):
        ret, frame = self.capture.read()
        #print('tick')
        self.imageBit = wx.BitmapFromImage(self.image)
        self.staticBit = wx.StaticBitmap(self.pnl, 
            wx.ID_ANY, self.imageBit)
        self.Refresh()
def main():
    app = wx.PySimpleApp()
    frame = viewWindow(None)
    frame.Center()
    frame.Show()
    app.MainLoop()
if __name__ == '__main__':
    main()

OpenCV is not a hard requirement (I'm open to other options as long as the solution is cross-platform. If I'm not mistaken, Gstreamer is not cross platform, and PyGame has been difficult to embed in wxPython, but I'm open to ideas). wxPython is a hard requirement.

Author: internet việt nam

Thank's a lot!

edit retag flag offensive close merge delete

Comments

imho, this is more a question about wxPython, and thus off-topic here.

berak gravatar imageberak ( 2016-01-26 04:08:28 -0500 )edit