Weekend hacking: Homebrew security camera with infinite recording length

24 January, 2011 § 1 Comment

I’ve seen people use security cameras before. Most cameras are set up in a way where the user puts in a VHS tape, presses record, and repeats this process over. If something happened during the recording, the tape will be saved as evidence, otherwise it will be rewound and recorded over again.

This always seemed like a lot of work for something that is purely reactionary. Let’s look at the scenario again. The user is proactively doing a lot of work in the hopes that they will be able to react. Put another way, if you make 20 dollars an hour, over a given month you might spend five or six hours rewinding and pressing record. If there is less than 100 dollars of damage caught on tape, then it wasn’t worth it.

So how about a different solution? At midnight on Friday I decided I would find something better. I had in mind a security camera that kept a circular buffer of the last 8 or so hours. If nothing happened then it would just overwrite what it had previously recorded.

Unfortunately I had no luck finding such a program on the internet, so I decided to write one myself. I first came across OpenCV, which is a free computer vision library. OpenCV is really powerful (and might be a lot of work). I sure didn’t want to write this in C++. Luckily I found technobabbler’s tutorial on how to make a simple webcam application using Python.

I followed the tutorial and had a simple application running that could save a snapshot from the webcam with a simple click of a button. By 4:30am I had a working prototype that was doing just what I wanted.

Using Python 2.5, VideoCapturePILpygame, and FFmpeg, I am able to keep the last 24-hours of snapshots (at 10 frames per second). If I ever want to save those 24 hours for reference, I simply hit the letter ‘s’ on the keyboard.

I’ve made this script open-source under the GPL license and hosted it at Google Code. Let me know what you think.

Python Unit Tests

26 April, 2009 § Leave a comment

Yesterday, I wrote my first project from scratch in Python using TDD and it was a pleasure.

The integration of unittests in the Python language took away many headaches that come from setting up an environment in other languages such as C++ or C#. To get started, just import unittest. The next step to configuring is to call unittest.main() from your main loop. That’s all the configuration necessary to start writing unit tests in Python.

When I was writing the tests, I followed Kent Beck’s recommendation to make a to-do list and I really liked how it turned out. The first thing I did was read through some of the documentation and write down different tests I could write. After writing them down, I picked the easiest one out of the list. Moving through the list this way made the work less stressful, not to mention the whole part about having the tests check to make sure everything works.

When I chose an item from the list I made it bold, and when I had finished it I put a strike through it. If anything came up while working on that item, I added it to the list.

The only hiccup that I ran into while working on it was IDLE’s improper handling of the unittest’s exit. When the tests are finished, they throw some type of exception. Apparently this isn’t a problem with other runtimes, so the way I fixed it was surrounding the unittest.main() with a try: and except:. Nothing is hidden from the developer if a unit test fails.

Google Summer of Code is upon us

22 March, 2009 § Leave a comment

I am currently looking for a Google Summer of Code (GSoC) project to participate in over the summer, particularly to get my feet wet with Python. This will be my first summer working on a GSoC project, and I will be doing so during the hours of 5pm – sleep, since I will continue to work full-time during the summer months in between semesters of my Masters in Computer Science at MSU.

I have used Python previously when I created a basic distributed checksum system for ensuring data integrity over time and am looking to see what interesting problems that are available for GSoC.

If you are l0oking to participate in GSoC, there is a delicious account set up with links pointing to all the different mentoring organizations and their project ideas that they have out there.

Where Am I?

You are currently browsing entries tagged with python at JAWS.