Monday, September 9, 2013

Raspberry Pi Journal #20

Installing Web Camera

Or How to Get a High End Deer Camera Really Cheap

I was shopping around at MicroCenter when I saw this cheap HP webcam HD 2200 for sale. I couldn't resist and bought one. So, the first thing to see if the camera would work right out of the box. And what do you know? It works fine.

There's a program called lucview that you can use to see if the webcam works, but I simply use the mplayer program that I already downloaded.

mplayer tv://

That will work just fine. Apparently, though, the cheap webcam has bad adjustment. It's fine under sun light, but when the room is dark, the blacks become blue and green. So freaky!

Next, it's video capture time. I'm using a program called motion. The program uses configuration file. It took me a while to notice that there is no command line parameters. In the end, I simply create a file called motion.conf and put it in my directory. Also notice, that if you have more than one, you also need to create motion1.conf, motion2.conf, and so on. Not that I will have more than one. Even using one, my Raspberry Pi goes to max CPU so easily.

pi@rustypi ~ $ cat motion.conf
#motion -c /home/pi/motion.conf
auto_brightness off
brightness 200
contrast 200

control_port 9001
control_localhost on
webcam_port 9090
webcam_localhost off
framerate 2
noise_level 255
noise_tune on
threshold 16400
threshold_tune off
max_mpeg_time 540

ffmpeg_cap_motion off
ffmpeg_cap_new on
ffmpeg_timelapse 2
on_motion_detected echo "motion is detected"
on_movie_start echo "Movie  %f is starting"
on_movie_end echo "End of Movie %f"

jpeg_filename cap%M%S
#jpeg_filename preview%T
movie_filename Movie%v
snapshot_filename shot%M%S
timelapse_filename tlapse
target_dir /home/pi/webcam_images

height 640
width 480
output_all off
output_motion off

Quite a long list of options, right? It uses 2 ports. One is for control, or the user interface for the program. Another is for webcam, or the viewfinder of the program. The viewfinder uses MJPEG stream, something Midori cannot handle. I eventually relented and use my Kindle Fire for it.

You can see the big monitor that is running Raspberry Pi, and I'm holding the webcam next to my Kindle Fire that is acting as my viewfinder. Talk about technological overkill! It works well enough, but that's quite a bit of technologies involved here. Oh, the blue box? That's my Nintendo 3DS XL. I'm using it to take the picture.

Hmmm. It looks like I'm using a bunch of cheap technologies, doesn't it? Does that means I'm a cheapskate?

Here is the view of the directory. I created a special "webcam" directory to hold the images. I'm thinking of moving it to external SD card, because of SD write wear problem.

The name of the files are different according to what you want to use. In this case, I'm using capHHMM format. There are lots of different format, depending whether or not you're capturing time-lapse and whatnot. The only thing I can tell you is for you to experiment.

I thought I was being clever and decided to capture screenshot via webcam. It turns out the lighting was atrocious and all I got was a bunch of colored dot. Not at all what I was looking for. I set the brightness manually, and brought it extremely bright lights. It works, in that the screen looks normal. It doesn't work in that the lighting was uneven. Either way, the result is unusable.

You know, I was thinking how this Raspberry Pi is really compact and that motion program is really powerful. Then it occured to me that I can duplicate the project as Deer Cameras.

I was looking through the Cabela's catalog, and it features lots of deer cameras, starting from $80 and up. So, I'm thinking, Raspberry Pi, battery, webcam, Wifi dongle. Those probably costs about $60. Tupperware for rain-proof enclosure, and you have the redneck equivalent of Raspberry Pi powered Deer Camera!

You'll run it headless, for sure. You can set it up anyway you want. In short really nice functionality of a high end deer camera for the price of the cheapest kind.

Well, there's one thing missing. It can't take picture in the dark. I suppose, you'll need infrared spotlight. Or heck, since we're talking about redneck version, just hook up multiple Million Candlelight Spotlight, set to trigger when the deer is in range. Just freeze those deer in multitude spotlights, good for taking pictures with webcam in the middle of the night!

No comments:

Post a Comment