February 20, 2014

Controlling Spycams with ZoneMinder on Linux (part 2)

In part 1, How to Operate Your Spycams with ZoneMinder on Linux, we learned how to connect and operate a single wireless IP camera in ZoneMinder. In part 2 we'll add a Webcam, create zones to zero in on just what we want to monitor, and watch multiple cameras at the same time.

Putting the Zone in ZoneMinder

When you're recording surveillance videos, you probably want motion-detected recording. Because even if you have vast disk storage and aren't worried about filling it up, it's time-consuming to review recorded events, so it's better to limit recordings to when something actually happens.

figure 1 ZoneMinder zones

And now comes the excellent part, and that is defining the zones you want to monitor, which is a powerful tool for eliminating even more clutter. It is likely that there are some irrelevant events in the field of view of your camera, such as traffic, changing light, moving leaves, and what-have-you. You can define multiple zones, set different alerting levels, and exclude some zones from triggering alerts.

When you set up a new camera it creates a new zone by default, which includes everything the camera sees. You can see this on your ZoneMinder console (figure 1). Click on the zone number to create a new zone. You'll see something like figure 2. Click Add New Zone. Give the new zone a name, and select the Fast, High Sensitivity preset. This fills in the relevant values for you, which of course you can tweak if you like. In my example I want only activity at the gate recorded, and exclude street traffic, and dogs and cats and goats running around in the yard (figure 3). Look for the drag handles at the corners of the image, and then drag them to create region points to define your new zone. You can have as many region points as you want to create irregularly-shaped zones, and you create new region points by clicking on one of the plus signs in the coordinates grid at the bottom.

fig-2 createzone

It can be a little tricky to position your region points, so try fine-tuning them by typing the values in the coordinates grid. The coordinates are simple X and Y axes. X is the horizontal position, and Y is the vertical position. To help remember, think "X is left and Y to the sky." Of course X is right and left, and Y is up and down. You can see which coordinate a region point belongs to by hovering the cursor over it. The whole zone is the size of your image in pixels minus 1, so a 640x480 image has a 639x479 zone.

You can also create inactive zones to screen out events you don't want to capture. Create a new zone that covers the area you don't want recorded, and then select Inactive in the Type dropdown menu.

fig-3 front gate

ZoneMinder supports multiple zone types and alarm check methods. I use Active and Inactive, and the AlarmedPixels alarm check method. These are the simplest to configure, and they do the job. To learn about more complex options, such as Blobs and Preclusive, consult the Defining Zones how-to in the ZoneMinder wiki. This also describes what the various min/max pixels values do.

Adding a Webcam

There are a number of wireless Webcams that work well with ZoneMinder. The Foscam FI8910W and FI8918W are nice wireless indoor cameras with infrared and pan and tilt, and their setup on Linux is similar to my FI8905W in part 1. (If you're thinking of using an indoor IR camera to peek outside, keep in mind you'll have to deal with reflections from your window, and the infrared is useless with a glass window in front of it.)

USB Webcams are even easier, so we'll run through adding a Logitech C310 Webcam. This is an inexpensive Webcam that I use for Google Hangouts and Skype, and it supports motion capture, so it makes a dandy inexpensive spycam. First connect it and then take a peek in lsusb to see if your system recognizes it:

$ lsusb
Bus 003 Device 013: ID 046d:081b Logitech, Inc. Webcam C310

Then fire up either Cheese or Gucview to verify that it works. Now go to your ZoneMinder console and click Add New Monitor. On the General tab give it a name, then:

Source Type is Local
Function is Modect
Maximum FPS is 15.

In the Source tab the Device Path is probably /dev/video0. Most newer Linuxes create /dev nodes dynamically, so you can look in /dev and use whatever is there. Then:

Capture Method = Video For Linux version 2
Device Channel = 0
Device Format = NTSC
Capture Palette = YUYV
Capture Width and Height = 640x480

You can use many other values than these; I know these work so it's a good starting point. Now go back to your ZoneMinder console, click on your new monitor name, and behold! There you are (or whatever your camera is looking at - figure 4).

fig-4 nerdcamFigure 4: Hello from the mad Linux nerd's lair!

Reviewing Events and Making Movies

In figure 4 you can see a list of time-stamped recorded events underneath the picture. Click any of them to watch. Note the wealth of useful options in the playback screen: Delete, Edit, Export, Archive, Frames, Stills, and Video. Click the Video link to create a video in .avi, .mov, .wmv, or other formats. If one doesn't work try a different one. You need to have ffmpeg installed, and OPT_FFMPEG checked in Options > Images.

When you want to mass-delete Events go back to the main console screen, click in the Events column, click View All, check the checkbox next to Thumbnail to select all, and then click Delete at the bottom.

Watching Multiple Monitors

When you have multiple monitors you can view all of them at once from the main screen, or have them cycle one at a time. On the upper right side of the main screen click Cycle/Montage to select the view you want. Control the Cycle interval in Options > High B/W- Medium B/W- Low B/W. The default is 30 seconds.

The Montage view has various layout and scaling options (figure 5).

fig-5 montage

When It Doesn't Work

Here we are at the end of part 2, and we've covered just the basics of using ZoneMinder. Be fanatical about buying only well-supported cameras, because life is too short trying to make something work when it doesn't want to. When things don't work right, try these steps:

- Unplug and re-connect USB cameras
- Restart ZoneMinder
- Check your ZoneMinder and Apache logs
- Visit the ZoneMinder Wiki and forums.

When you solve a problem please share it in the forums or Wiki, because the world of surveillance cameras is vast, so the more we all help the better.