Peep-holes are wonderful things. When someone knocks on your door, it is the peep-hole that lets you decide whether you feel like answering. Unfortunately, having to get up and see who is there wastes valuable blogging time! The solution: get someone to watch the door for you! And who is better suited to that task than an old Logitech QuickCam.
How it went down:
1) Webcam placed up against peep hole. Problem! The image from outside is about 50 pixels big, and unrecognizable because the camera isn’t close enough to the peep-hole lens, the resolution is low, and the camera’s lens is rather wide-angle.
2) To get the camera closer to the peep-hole’s optics (in the hole), I removed the camera from its plastic casing (a white sphere, designed to look cool, but rather bulky) and investigated it. The lens screws into a dust-proof plastic cover over the CCD on the PCB (see image below) and is attached to a rather large lens flare / focus knob. To get it to fit I dremmeled the lens flare down to the width of the threads. The lens was still too big so I removed the room-side of the peep-hole assembly, set it aside, and now the lens fit! I used rubber splicing tape (which is second only to duct tape in my book) to hold the hall-side in-place.
(the 320×240 CCD chip inside it’s dust shield)
3) Now that peep-hole image takes up a respectable portion of the web-cams field of view, I duct taped the sucker into the peep-hole, and used a 10ft usb cable to reach my trusty Pentium III server.
4) To capture and record only the motion which occurs outside my door I use the linux command -line tool called ‘motion‘, which I learned about in Linux Desktop Hacks, a book I highly suggest to any Linux user. Motion has some realy smart default settings and all you have to do is go: motion and motion watches the first video device (/dev/video0) for motion and takes a jpeg snapshot (or mpeg videos!) of each frame that changes significantly. It even has a web interface for controlling it!
5) Unfortunatly, motion’s web interface doesn’t give you a live feed from the cam, or let you look at the logs. So I had it dump it’s jpegs into /var/www/motion/ on my server (by being in that directory when running motion) and used a simple php script to display all the images in a row. The coolest part of the page with all the photos is that if you scroll fast enough, it makes a video! Here is a taste of what the motion output looks like in firefox:
6) I decided to stop recording because I don’t want to invade people’s privacy, so I just display the live feed on a monitor above my desk. Of course, hallways are not for privacy, but it kind of freaked me out seeing the every motion of people on my floor… it’s so, clockwork. Anyway, with the monitor over my desk I don’t have to stop blogging to see who is at the door!
By the way, I could not find a real-time local webcam viewer for linux (or windows for that matter) that can do scaling. I need to scale the image 6X so I can see the image from across the dorm… so I modified Jaromil’s hasciicam, added SDL rendering and scaling to get what I wanted. The code is a real hack job, but it is good if you want to mess around with webcams in linux (using Video4Linux), which is hard to do if you are just staring at an API spec!