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 &amp; 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.
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.