Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient Background subtraction with OpenCV

I want to do background subtraction in a video file using OpenCV method. Right now I'm able to do background subtraction, but the problem is that I couldn't get the output in color mode. All the output after subtracting the background is coming in grayscale color mode :(. I want to get the color information to the foreground which is the resulting output after background got subtracted.

Can I do it using masking technique?? like the following procedure which I'm thinking about.

  1. Capture Input -- InputFrame (RGB)
  2. Process InputFrame
  3. Subtract background, store foreground in TempFrame (which is coming in grayscale :( )
  4. Create a mask using TempFrame
  5. Apply the created mask to the InputFrame
  6. Get colored foreground as OutFrame

I'm struck up with doing the masking using OpenCV. I'm just a very beginner in OpenCV. Please help me to overcome this.

Thanks in advance.

like image 706
Jabez Avatar asked Jan 08 '10 09:01

Jabez


People also ask

What is MOG background subtraction?

Background subtraction (also known as Foreground detection) is a computer vision algorithm that tries to distinguish foreground objects from the background.

How do I subtract two images in OpenCV?

You can subtract two images by OpenCV function, cv. subtract(). res = img1 - img2. Both images should be of same depth and type.

How does Knn background subtraction work?

The K Nearest Neighbor (KNN) method computes the Euclidean distance from each segment in the segmentation image to every training region that you define. The distance is measured in n-dimensional space, where n is the number of attributes for that training region.


1 Answers

http://vimeo.com/27477093

code is here

http://code.google.com/p/derin-deli-mavi/downloads/detail?name=denemeOpenCv23.zip&can=2&q=

to reach a colored foreground just copy image by using foreground mask

// image.copyTo(foreground,foreground);

like image 135
Birol Kuyumcu Avatar answered Oct 21 '22 04:10

Birol Kuyumcu