Ask Your Question

scubindu's profile - activity

2016-01-26 03:29:13 -0600 asked a question Problem about background in opencv 2.4.8

Dear all member!

The following program displays 'foreground' completely black and not 'frame'. I also checked that all the values in 'frame' is equal to the values in 'foreground'. They have same channels,data type etc. I am using python 2.7.6 and OpenCV version 2.4.8

import cv2 import numpy as np

def subtractBackground(frame,background):
    foreground = np.absolute(frame - background)
    foreground = foreground >= 0
    foreground = foreground.astype(int)
    foreground = foreground * frame
    cv2.imshow("foreground",foreground)
    return foreground

def main():
    cap = cv2.VideoCapture(0)
    dump,background = cap.read()

    while cap.isOpened():
        dump,frame = cap.read()
        frameCopy = subtractBackground(frame,background)
        cv2.imshow('Live',frame)
        k = cv2.waitKey(10)
        if k == 32:
            break

if __name__ == '__main__':
    main()

Thank's a lot!

2016-01-26 03:18:26 -0600 asked a question Question about image from webcame in opencv

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!