You are here

CCTV as designed by a computer scientist

For several years now I've been slowly building up a computer controlled CCTV system. Naturally, I'm not going to be satisfied with pointing a camera out the window and saving plain old video to disk. Although I have yet to do any proper study of the subject, I am fascinated by computer vision and this is an ideal platform for me to mess about with in my spare time. And, wondrously, the result of my hacking around is something worth using!

Here's a quick description of my system. I started building it in late 2005 and have added to it in fits and starts over the years. The computer vision part was implemented this weekend based on perl scripts I originally prototyped at the end of 2006.

CCTV cameras are wired to a standard DV card with composite inputs.
This card is in machine 1.
'motion' is run on machine 1 which detects movement within the field of vision of each camera.

On detecting movement:
* frames from the camera start spooling to disk.
* additionally, a number of preceding frames are dumped to disk from memory.
* a perl script is fired off for each movement detection (script 1).

A cleanup script (script 2) is called each hour to maintain storage by removing old images.

Script 1 takes the meta-data of each event:
* if the movement/event that has been detected is not significant, the script exits.
* if an alert has been raised in the last n seconds, the script exits (this is intended to smooth a 12 FPS stream down to something manageable - the script initially sent SMS).
* the data about the event is inserted into an Oracle 10g database running on machine 2.

Machine 2 runs a script (script 3) which polls this database, looking for new events.
On finding an event:
* the corresponding image is fetched over NFS.
* an image from the seconds directly preceding the event is chosen and also fetched over NFS.
* using these two images, the object which caused the motion-detection is extracted and handed over to an analyser.
* the analyser picks out details regarding the object and hands these to a classifier.
* the classifier decides what the object is most likely to be:
- a raindrop, insect, cat, bird, person or vehicle.
* this extracted information is pushed back into the database.

From the classification of the object and the time of day, the software can decide whether to send an email, an SMS, call a phone number using VoIP or do nothing. From here an output controller can be added fairly easily added allowing the CCTV to do things like switching on lights.

The computer vision scripts are written in perl and as such aren't overly fast. A frame takes 30 seconds or so to analyse, hence the two part system. Machine 2 is also much faster than machine 1 hence the offloading of CV tasks. Of course, I know that my code is sub-optimal in many ways.

My intention is to rewrite the image processing in Java. My perl stuff tends to be for prototyping, but if I think that I can't improve it then I'll leave it in perl. In this case, rewrites in a compiled language is certainly near the top of the list for the thing I'll need to do next.