📜 ⬆️ ⬇️

Create a video surveillance system using motion

In this article I want to talk about setting up and using a home tracking system. You can do any area within your webcam’s view, send yourself a message when activity in this area is detected, take pictures, broadcast the image over the network (you can use authorization to access video from your webcam and watch remotely if you have a static ip) whatever you want - complete control and freedom of choice, which is generally characteristic of gnu / linux and similar systems (in the future we’ll talk about linux).

So, I present to your attention a wonderful utility - Motion , distributed under the GPL license. Most likely it is already in the repository of your distribution, if not (although I doubt it) - you can download deb, rpm or source code from the download page on the off site. I used the tools of my package manager.



You can run, but it is better to first customize it for yourself. The configuration file is stored in / etc / motion (it is better to copy it to the user's home directory, you can specify the path to the config with the -c option). Edit it with vim /etc/motion/motion.conf
')
This file is well commented out, and if you have no problems with English, then understanding the options for yourself is not difficult.

First option:
daemon (on/off) - whether motion will start in daemon mode (in background). You can also specify the -n option at startup, then the program will run as usual.

Further:
videodevice /dev/video0 - we specify our video device. I have this / dev / video0.

rotate (0,90,180,270) - rotate the image by a specified number of degrees (if the camera is attached at an angle)
width 320
height 240

- width and height of the image in pixels, respectively

framerate (2-100) - the number of frames captured per second. Naturally, the greater the value, the greater the consumption of computer resources. Choose the optimal value.
minimum_frame_time 0 - after the previous option - allows you to set the minimum time between capturing two frames. You can, for example, capture a frame every 5 seconds.

netcam_url value - use if access to your camera is via a network. instead of value, specify the path to the video stream. By default, this option is not used.
auto_brightness off
brightness 0
contrast 0
saturation 0
hue 0

- brightness, contrast, saturation, etc.

The next important section for us:
# Motion Detection Settings:
threshold 1500 - can be described as sensitivity to determine movement. The smaller the value, the more sensitive the detector.
noise_level 32 - noise level. Allows you to ignore the noise created by the camera. Set the optimum value for your camera.

area_detect (1-9) Allows you to area_detect (1-9) only a specific area. 1 - upper left corner, 2 - upper middle part, ... 5 - center, ... 9 - lower right corner.

mask_file value - Specify the path to the pgm file with a motion mask that does not need to be fixed. Allows you to ignore the rocking branches of trees, etc. For more information about the pgm files here netpbm.sourceforge.net/doc/pgm.html

Next come a few more options for defining the motion and encoding options for the image and video. I will omit their description.

snapshot_interval N - Creates snapshots every N seconds.
locate (on/off) - draw a frame around a moving object.

target_dir /usr/local/apache2/htdocs/cam - The folder where the images will be saved. I set this value ~ / motionshots

snapshot_filename %v-%Y%m%d%H%M%S-snapshot
jpeg_filename %v-%Y%m%d%H%M%S-%q
movie_filename %v-%Y%m%d%H%M%S

- Customize file names.

on_event_start value
on_event_end value
on_picture_save value
on_motion_detected value
on_area_detected value
on_movie_start value
on_movie_end value
on_camera_lost value

- Performs a specific action upon the occurrence of certain events. As value, you can specify a script, for example, sending you a message. Or, for example, to include music when someone is found. Everything is limited by your imagination and depends on your goal.

Now you can run
motion [-c ///] . You can also add to the list of daemons of your system (rc-update add motion default for ghetts, for archa - add to DAEMONS = () in /etc/rc.conf, for other distributions I don’t know for sure, but this is not more difficult)

Now, when detecting activity in the monitored area, the program saves snapshots to the specified directory and executes your script (there are many articles about writing scripts to send messages, so I will not cover this topic in this article).

And finally, some screenshots with an example of use. As you can see, when motion is detected, motion in non-daemon mode displays lines like [1] File of type 1 saved to: /home/vladimir/motionshots/01-20110727140020-00.jpg





UPD: Thank you for the invite! Topic moved to Linux for all

Source: https://habr.com/ru/post/125216/


All Articles