Last week I wrote about the Raspberry Pi, the camera module and Motion acting as a surveillance camera. I’ve been testing my Raspberry Pi surveillance camera for a week now and the results are satisfying although there are also some problems. I think much of the succes of the camera comes down to finding the best settings of the /etc/motion.conf file of Motion for a given scenario. The motion.conf file enables you to setup the Motion program. Everything from camera settings to motion detection can be changed in this file.
|Image from a motion video. If someone (in this case my son) is entering our backyard it is perfectly recorded by Motion.|
I want my surveillance camera to record anyone entering my backyard but this sounds easier than it is. If the threshold parameter in motion.conf is too low all kinds of events are recorded that are completely irrelevant. E.g. on a rainy day raindrops falling on the window are recorded. With higher threshold values I might miss something relevant. After experimenting with different values of the threshold I found that a value of 1500 works best in my case.
On a sunny day bright sunlight can fall onto the camera lens causing lens flare. This reduced contrast and color saturation (see image below). More importantly the Motion program detect changes in lens flare as motion and records them. I think problem can easily be solved with some kind of lens hood.
|Lens flare caused by sunlight reducing contrast and color saturation.|
A whole different problem is motion detection at night. My camera, the regular Raspberry Pi camera module, is just not up to this task. For detection at night I’ll need the NoIR Pi camera. This camera has no infrared filter. As a consequence colours at daylight look odd but you’re able to record at night, but only with infrared light illuminating the subjects. Several add-on boards for the NoIR Pi camera are on the market that do just that. These boards fit right over the camera module.
|The regular Raspberry Pi camera module is useless at night.|
Proper file permissions
I created a directory /home/pi/Camera on the Raspberry Pi. I want all my video files to be stored in this place however before Motion is able to do this I had to change the permissions. Motion (the Program) creates it’s own user motion so this user needs proper permission in the home/pi/Camera folder (that is created by the user pi). To do this I first changed the group ownership of the folder:
chgrp motion /home/pi/Camera
And next give the group the proper permission:
chmod g+rwx /home/pi/Camera
The number of motion video’s that are stored on the Pi increase rapidly over the days. My backyard is quiet but not that quiet (not to mention the false positive that I described above). Since the Raspberry Pi stores the files on an SD card I will easily run out of storage space. So I need a method to remove the files automatically e.g after five days. Cron is perfect for this since it let me schedule commands or scripts periodically. I wrote a shell script that removes avi files created by Motion older than five days and added this to my crontab file to be executed daily. The key command in this script is:
Copying files to a PC
Whenever I want to check the motion files (e.g after one day) I copy them to my iMac using scp from the OSX terminal and then created a playlist in VLC by dragging all the files into it. The harvest of that one day is then displayed.
scp firstname.lastname@example.org:Camera/*.avi to/destination/folder
Next I’ll test the surveillance camera further until I’m satisfied with the settings and build a proper housing for the camera. Possibly I will switch from the regular camera module to the NoIR camera.