PeakGen
PeakGen

Reputation: 23035

Is it possible to detect a moving object in OpenCV?

I am asked to write a code which can detect ANY moving object using OpenCV. It will be used in out-door system. But, any moving object? According to my knowledge it can detect pre-defined objects like human, car, ball etc. I am not sure about this Any object, because the trees also moving to wind which has no use to the system and if the system is going to detect moving branches of the trees, moving waves of the water and useless stuff like that it will be a big issue.

Is there any way in OpenCV where we can detect all useful moving objects like humans, cars, vans, animals etc and not useless things like moving branches of the trees, moving waves of the water etc.

Some people told me "pattern Recognizing" will help but I have no time to move with it, I got only 4 months and I am not a Math person. Anyway, if this can be easily used with video OpenCV, then I can think about it.

Upvotes: 1

Views: 8000

Answers (2)

Alexey
Alexey

Reputation: 5978

Look into background/foreground segmentation methods. They are used to segment out (detect) moving objects by using statistical methods to estimate background. OpenCV version 2.4.5 offers a number of different implementations for background subtraction, namely

  • BackgroundSubtractorMOG
  • BackgroundSubtractorMOG2
  • FGDStatModel
  • MOG_GPU
  • MOG2_GPU VIBE_GPU <- listed under non-free functionality
  • GMG_GPU

There is a demo source code bgfg_segm.cpp located in {opencv_folder}\samples\gpu. The demo shows usage and displays output for the segmentation classes (on GPU). There is also a similar demo for CPU, just look for it. GPU-based classes offer real-time performance.

The approach will output objects as contours or as masks. After detection you can remove some false positives and noise by applying morphological operations, such as dilation and erosion. In addition, you can only keep contours that has an area large enough (so that leaves, which are small, might be filtered out).

Upvotes: 3

Abdul Rehman
Abdul Rehman

Reputation: 2346

No, you don't have to reinvent the wheel. There are plenty of examples over net to detect moving objects you can google about motion.

The simple method to accomplish this is just detecting back ground, having the reference of previous frame and subtracting the new frame. the subtracted image will contain the information about the regions of motion or any thing that changed on the screen(frame)

About detecting the objects, You can rectify the regions according to the motion and you can specify the threshold value of motion and the can grab the objects by binarization

Upvotes: 4

Related Questions