13

I recorded my 1 year old son in sleep with a night vision camera (to monitor twitching).

I now want to automatically create a video containing all movement, e.g. I want to filter only the frames that are affected by a detected motion.

I tried VLC with motion detection and it works, but there is no way I can tell VLC to just show me the frames that contain motion.

2

3 Answers 3

6

This is the sort of thing that you can knock up quite quickly using OpenCV and Python.

  • Free (both gratis and FLOSS)
  • Cross platform: Windows, Linux, Android and Mac OS
  • Motion Detection algorithms built in, (including being able to set thresholds).
  • VideoWriter class to save your results
  • Active user community.

Just download and install: Python, OpenCV, the python libraries Numpy and pyopencv.

Example of motion detection in OpenCV in python

This example came from the blog of Matthias Stein.

import cv2

def diffImg(t0, t1, t2):
  d1 = cv2.absdiff(t2, t1)
  d2 = cv2.absdiff(t1, t0)
  return cv2.bitwise_and(d1, d2)

cam = cv2.VideoCapture(0)

winName = "Movement Indicator"
cv2.namedWindow(winName, cv2.CV_WINDOW_AUTOSIZE)

# Read three images first:
t_minus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
t = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)
t_plus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)

while True:
  diff = diffImg(t_minus, t, t_plus)
  cv2.imshow(winName, diff) # This shows the delta image
  # Here you would use diffImag to save the frame if the difference is bigger than some threashold

  # Read next image
  t_minus = t
  t = t_plus
  t_plus = cv2.cvtColor(cam.read()[1], cv2.COLOR_RGB2GRAY)

  key = cv2.waitKey(10)
  if key == 27:
    cv2.destroyWindow(winName)
    break

print "Goodbye"
5

https://github.com/Breakthrough/DVR-Scan

DVR-Scan is a cross-platform command-line (CLI) application that automatically detects motion events in video files (e.g. security camera footage). In addition to locating both the time and duration of each motion event, DVR-Scan will save the footage of each motion event to a new, separate video clip. Not only is DVR-Scan free and open-source software (FOSS), written in Python, and based on Numpy and OpenCV, it was built to be extendable and hackable.

I can confirm that it works perfectly with MPEG4 (H264) AVI files.

Usage:

dvr-scan -i some_video.mp4 -o some_video_motion_only.avi

2
  • Tried to install DVR-Scan on three different computers (Windows). Program did not open. Does it still work? Is there something I’m doing wrong? Apr 21, 2020 at 15:47
  • The current version is working absolutely fine for me (Windows 10)
    – Andreas
    Dec 5, 2021 at 12:08
0

There is a software from safeware: SafeMotion. http://www.safeware.ca/support.php It worked pretty well for me. Perhaps it will solve your problem. Safemotion is a helpful program that enables you to export all the videoparts with movement. Moreover you can define zones in which movement should be detected and you can adapt the size of the moving object and the sensitivity. Just used for analysing mice behaviour videos, to not watch the sleeping scenes.

The software is freeware, but I think there hasn't been an update for quite some time. It has no GUI, but there is a way of adjusting it by command line, to adjust for example sensitivity: safemotion.exe -m 7 XXX.avi

m= Scale of movement objects in detection between 1-2

5
  • Getting better :-) A few more things: Is it free forever? If not, please include price information. Also, please include a screenshot of the screen where you can set the sensitivity, thanks! :-)
    – Nicolas Raoul
    May 15, 2017 at 11:10
  • Also, what is your relationship with that company?
    – Nicolas Raoul
    May 15, 2017 at 11:11
  • I have no relationship with this company at all. Just had a long week of searching for software to solve the same problem. So I did a lot of reading in forums, googled and tried different things. VLC unfortunately didn't work for me. The software I mentioned is freeware, but I think there hasn't been an update for quite some time. There is no GUI, so no screenshot, but there is a way of adjusting it by command line. It's explained in the readme.
    – Nathalie
    May 15, 2017 at 18:36
  • I see! Could you please post an example command line that shows how to set the sensitivity? Thanks!
    – Nicolas Raoul
    May 16, 2017 at 6:15
  • Please also mention the price/updates in the body of your answer. Comments get deleted. Cheers!
    – Nicolas Raoul
    May 16, 2017 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.