# Motion detection one threshold over dataset

We're working on a project where we have to detect the moments where motions happen in a medical scene. I have a data set of 20 videos that are closely resemble (Same camera & configuration used, same shooting/environment conditions etc...). Here is what I did for each video:

• Compute the optical flow (Farneback) between 2 consecutive images (t-1, t)
• For each couple of images (t-1, t), compute the Norm1 of the displacement vector of all the pixels and then get the mean of these values. Then, I represent each couple of images by the mean of the Norm1 of optical flow results.
• By doing so, I could draw a signal that represents the variation of these values as you can see below (Example video #1)

• We zoom on the first 100 seconds of this signal to see the following:

To be able to detect the motions in video #1, we can just use as threshold the value 0.2 so we can differentiate between motion and not. But to be able to handle similar cases, we have to set a threshold at application/project level not on a video level: the threshold should be applicable over all the videos and for any new video of the same type. Let's take a look over the same kinda signal for video #2:

Obviously, the threshold in this case is 0.25 which is different from 0.2, the one we used for video #1 . To have a robust solution, we shall have one threshold per application so my question is about how can we use these thresholds (choosed manually) to have a global threshold for this application?

P.S: We already tried to use the mean of all these thresholds but it didn't work.. It failed to detect some important motions. We're asking such a question here because we just want to know if there is a fundamental principle to follow in such cases.

• Hm, two examples is still quite a low sample size, but could it be that your threshold is approximately 1.5 times the mean value of your signal?
– M529
Commented Dec 4, 2020 at 15:53

I could suggest several things. I am not sure if you already try them and I am not sure of the requirements either. Assuming that you need real-time analysis and performances:

• What about normalizing the signals?
• What about using some naive techniques such as zero-crossing rate? Thinking in you need real-time performance.

If it is offline analysis:

• What about nomalizing the signals? + Detrending + Drift filtering.
• Frequency analysis

Cheers.

you should filter the data before you use the threshold. Run a low pass filter on the 1D signal (convolution with a Gaussian) and than normalize the data to the range between 0-1 after that i think you will be able to find a global threshold.

• I already did it. In the images above, you can see clearly the green signal. which is the result of median filter. By comparing the results of this filter for both videos, we could see that we have the same problem.. The threshold can't be the same for both videos. Commented Aug 26, 2016 at 9:30
• Normalize the data to the range 0-1 Commented Aug 26, 2016 at 9:57