So its Saturday afternoon and you have nothing to do. As you glance around your room you spot a half full beer, a webcam, and that linux box that you have been wondering what you were going to do with. Seriously, why did you buy that piece of crap webcam anyway? A quick google search reveals that you might have a hard time even getting that thing working in XP, let alone your preferred OS of choice, OSX. =)
Ok, I know what to do. First dont drink that beer.. Its old. Throw it away and clean up your room a little bit. Then go get another beer -- and lets try to finish this one Nancy. As you sit back and nurse your new beer you notice that your Asus EEE with BackTrack4 is in a somewhat different place than you left it. Instead of simply plotting your revenge on who ever you feel deserves the blame, lets try catching them next time red-handed.
The following will walk you through setting up a video-surveillance system that will detect motion, enable your webcam, take pictures of the intruder, and upload the pics online and notify your cell phone via an twitter SMS message.
You will need:
- USB Webcam
- Linux installed on a machine (I will use Ubuntu "Gutsy Gibbon" in my example, but should be similar for other Linux distros)
- All ways on internet connection
Before we begin, you will want to make sure your webcam is supported by your Linux distro. First lets check to see if it works out of the box. Turn on your machine and login. Plug in your USB video camera and open a terminal window. Type:
lsusb |
to determine if your webcam was detected. Your output should look something simiar to:
hevnsnt@linuxbox:~/motion$ lsusb |
(Although of course your output will match your configuration)
Record the bus location and device id of your webcam. (Bus 002 Device 006 in this example.) Now open "Ekiga Softphone" (installed by default in Ubuntu under Applications / Internet / Ekiga Softphone).
We are going to use this application to make sure that your USB camera is working (so far without ANY WORK!) You might have to click the camera icon, and if everything works, you should be getting a live picture. If not, check your Ekiga Preferences (Edit/Preferences/Video Devices) and change your input device to the device you discovered earlier. If this doesn't work you should Google for the device ID plus Linux driver. (eg 0553:0002 linux driver) Come back to this tutorial when you get it working. If you cant get it working check craigslist.org for a newer camera, but I doubt you will need to. Seriously If I got this crusty old zoom 1595 camera working, I am sure you can get yours working.
Detecting Motion:
In order to detect motion, we are going to use a software motion detection package appropriately titled "motion". Now since I know you probably are on a debian Ubuntu machine, so you are thinking "Oh this will be easy, apt-get install motion". Well you did get one thing right, it will be easy, but we are not going to use apt-get. The ubuntu repositories still have a much older version of "motion" than we want. To get the latest version (this tutorial was written using build 3.2.11) open a terminal window and type the following commands: (note this will download and install a .deb, you could always install from source)
mkdir ~/motion |
Congratulations, you have installed motion. Yeah Ubuntu! Now you just need to configure it. And let me tell you, there is A TON of configuration options, luckily it comes with a very well commented configuration file located at /etc/motion/motion.conf. Should you want to tweak your installation later, I would start with this configuration file.
However, for the sake of quicky-ness, I will share my configuration file that I spent a lot of time tuning and testing for my setup. Save it to ~/motion/motion.conf
# TwitterSecuritySystem motion.conf ############################################################ # Start in daemon (background) mode and release terminal (default: off) # File to store the process ID, also called pid file. (default: not defined) ########################################################### # Videodevice to be used for capturing (default /dev/video0) # The video input to be used (default: 8) # The video norm to use (only for video capture and TV tuner cards) # Rotate image this number of degrees. The rotation affects all saved images as # Image width (pixels). Valid range: Camera dependent, default: 352 # Image height (pixels). Valid range: Camera dependent, default: 288 # Maximum number of frames to be captured per second. # Minimum time in seconds between capturing picture frames from the camera. auto_brightness off ############################################################ # Threshold for number of changed pixels in an image that # Automatically tune the threshold down if possible (default: off) # Noise threshold for the motion detection (default: 32) # Automatically tune the noise threshold (default: on) # Despeckle motion image using (e)rode or (d)ilate or (l)abel (Default: not defined) # Ignore sudden massive light intensity changes given as a percentage of the picture # Picture frames must contain motion at least the specified number of frames # Specifies the number of pre-captured (buffered) pictures from before motion # Gap is the seconds of no motion detection that triggers the end of an event ############################################################ # Output 'normal' pictures when motion is detected (default: on) # The quality (in percent) to be used by the jpeg compression (default: 75) ############################################################ # Locate and draw a box around the moving object. # Draws the timestamp using same options as C function strftime(3) # Draw characters at twice normal size on images. (default: off) ############################################################ # Target base directory for pictures and films # File path for snapshots (jpeg or ppm) relative to target_dir # File path for motion triggered images (jpeg or ppm) relative to target_dir ############################################################ # The mini-http server listens to this port for requests (default: 0 = disabled) ############################################################ # TCP/IP port for the http server to listen on (default: 0 = disabled) ############################################################ # Do not sound beeps when detecting motion (default: on) # Command to be executed when a picture (.ppm|.jpg) is saved (default: none) # Command to be executed when a camera can't be opened or if it is lost |
Notification of Motion:
Now for the fun part, if you used the above configuration file at this point your system is configured to detect motion, and then snap a picture. It also is configured to save the "best" picture, and outline the movement that it captured. Yeah so what. Lets use kick it up a notch by using Web2.0 tools to notify us so that we can take appropriate action.
First create ANOTHER (assuming you already have a twitter account) twitter account, naming it something like mySECURITY or something that is specific to you. You will not give this name out to anyone so feel free to name it whatever you want. I gave my new twitter account an profile image of a security monkey.
In order to upload the motion-detected captured picture utilizing twitter (and more specifically twitpic) we are going to need call a script written by rtadlock at http://rtadlock.blogspot.com via the motion.conf. (these lines are bolded above) Save the following as ~/motion/updateTwitter.pl
#!/usr/bin/perl use strict; # Values to use when uploading to TwitPic # These can be changed if the TwitPic API GetOptions( "help|h|?" => sub { Usage() && exit( 0 ) }, if( !$picture || !$username || !$password ) if( ! -e $picture || ! -f $picture ) if( $verbose ) my $response; if( $uploadOnly ) if( !$response->is_success ) if( $verbose ) # I guess we could actually use XML::Parser to parse this, but it's kind of # If verbose, print out the response, so the user can access the picture } sub Usage() print "--username\tYour Twitter.com username\n"; } |
Putting it all together
At this point you should have:
- motion installed
- motion.conf located in your ~/motion/ folder
- updateTwitter.pl located in your ~/motion/ folder
- A new twitter account created, and all relevant user/pass information updated in both motion.conf and updateTwitter.pl
In your terminal type the following:
motion -n -c ~/motion/motion.conf |
If everything goes right, you should start capturing images, storing them into your ~/motion/ directory, and updating your new twitter feed. Now all you need to do is simply follow your new twitter account with your original one, and allow for device updates.
Now whenever somone comes into range of your camera, it will take a picture, upload to twitpic, and then send your cell phone a SMS message notifying you. If you have a web enabled phone, you can see the pictures in real time!
0 comments:
Post a Comment