Motion Detection Using OpenCV

I see requests related to opencv motion detection, but my requirement is much simpler, so I ask the question again. I would like to analyze the video frames and see if something has changed in the frame. Any kind of movement occurring in the frame is recognized. I just want to be notified if something happens. I do not need to track / draw outlines.

Attempts :

1) Pattern matching using OpenCV (TM_CCORR_NORMED).

I get a similarity index using cvMinMaxLoc &

if( sim_index > threshold ) "Nothing chnged" else "Changed 


Problem with :

I could not find a way to decide how to set the thresholds. The meanings of false coincidence and perfection were very close.

2) Method 2
a) Make a medium medium b) Take the abs. the difference between the current frame and the moving average.
c) The threshold is what made it binary
d) Count the number of non-zero values
I’m stuck again in how to generate it, because I get a large number of non-zero values ​​even for very similar frames.

Please give me advice on what approach I should take. I am going in the right direction using the above two methods or is there a simple method that can work in all the most common scenarios.

+4
source share
1 answer

Method 2 is usually considered the easiest motion detection method and is very effective if you do not have water, trees swaying or very changing lighting conditions in your video. Usually you implement it as follows:

 motion_frame=abs(newframe-running_avg); running_avg=(1-alpha)*running_avg+alpha*newframe; 

You can set the motion_frame threshold if you want, and then count non-zero values. But you can also just sum the motion_frame and threshold elements that are instead (it’s mandatory to work with floating point numbers). Optimizing the parameters for this is quite simple, just create two trackbars and play with it. Typically, alpha is about [0.1; 0.3].

Finally, it is probably too difficult to do on all frames, you can just use sub-election versions, and the result will be very similar.

+3
source

All Articles