Home

Forums

Statistics

Surveys

Top Ten

Your Account


Login
Nickname

Password

Security Code: Security Code
Type Security Code

Don't have an account yet? You can create one. As a registered user you have some advantages like a private journal and posting comments or additions to articles.

Who's Online
There are currently, 14 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here

Donations
If you find the information here useful,
help keep this web site online with a donation!
YTD Donations
$1.00
Thank You!

Host referer


  
Perl Script to Grab Picture from a Network Camera
Posted on Tuesday, May 16 @ 13:53:57 CDT
Topic: 4: Network based camera server and PTZ

The script in this example can be used to grab a webcam or network camera image.

It is a simple Perl script.  You just need to adapt the settings to fit your configuration.

You could also implement it using CRON.

With these two simple scripts, you can get MisterHouse to take a snapshot from a network camera, based on any MisterHouse event.  I am using an X10 tricky interface from my alarm system called $alarm and an Axis network camera server.

First make a file called MH/bin/get_cam
This is perl code that will retrieve a snapshot from your network camera.
$storedir should be set to the location you wish to have the picture placed.
$camurl is where you could point your browser to see a snapshot from your camera.
IMPORTANT: Right-click on your video camera's picture feed and choose "properties", then paste the URL into a new browser window.  You should see ONLY the snapshot in the browser window!
Some cameras offer a motion -or- refresh image feed.  Choose refresh image feed, then drill down to the jpg source. If your camera does not serve still pictures, the script here is unsuitable.
WebCam2000 is a program that will turn a Windows computer - that has a webcam - into a suitable source.

$basename plus HHMM timestamp plus $ext equals the stored filename.
So with the settings below, at 10:48PM, the filename would be Cam1-2048.jpg
remember there are 1440 minutes in a day, so you could end up with 1440 files!
(that's why I didn't add seconds or date to the filename, if you want to - it's your hard drive!)

    #!/usr/bin/perl -w
    use strict;         # Enforce safe programming
    use warnings;       #
    use File::Basename; # file name handling
    use LWP::Simple;    # WWW interface, exports HTTP::Status

    # Force the output buffer to flush
    $| = 1;
    # Set default values
    my $storedir = "/home/public/monitoring/";
    my $basename = "Cam1-";
    my $camurl = "http://net.cam.I.P/fullsize.jpg?camera=1&clock=on";
    my $ext = ".jpg";
    my $s = "0";
    my $m = "0";
    my $h = "0";
    my $mday = "0";
    # If the storage directory does not exist, create it.
    if( ! -e $storedir )
    {
    mkdir( $storedir ) || die "Could not create $storedir: $!";
    }
    # Generate file name
    ( $s,$m,$h,$mday ) = localtime( time );
    if( $s < 10 ) {$s = "0$s" }
    if( $m < 10 ) {$m = "0$m" }
    if( $h < 10 ) {$h = "0$h" }
    if( $mday < 10 ) {$mday = "0$mday" }
    my $fullFilename = "$storedir$basename$h$m$ext";
    # Get the file and store it locally
    my $response = getstore( $camurl, $fullFilename ) || die "Could not create $fullFilename: $!";
    # Check for a valid 'get' (RC_OK defined in HTTP::Status)
    if( $response == RC_OK )
    {
    if( -z $fullFilename )
    {
    print "File was 0 bytes. Removing.";
    unlink $fullFilename;
    }
    }
    else
    {
    print "HTTP response was $response. Could not download the image.";
    }
    exit 0; # =========== End of Main Program ===========
    

Don't forget to CHMOD the file so it has execute permissions.

Next you need a new user code file.  Store it in your MH user code directory.
i.e: MH/Code/Test/camtrigger.pl

if (state_now $alarm eq 'motion') {
    run 'get_cam';        
}

Remember to use the state_now function so that there isn't a picture taker spawned every loop!
(which is milliseconds!) Then activate the user code in MisterHouse.

By making several files and naming them get_cam1, get_ cam2, ect... you can have MisterHouse take pictures from multiple cameras.

You could use the time_now function to have a picture taken at a specific time every day.

You could set a timer, and take a picture every 5 minutes.

Remember: Questions can be posted in the FORUM section !


 
Related Links
· More about 4: Network based camera server and PTZ
· News by anoldman


Most read story about 4: Network based camera server and PTZ:
1: Axis 240 Camera Server and VTEL SMARTCAM


Article Rating
Average Score: 0
Votes: 0

Please take a second and vote for this article:

Excellent
Very Good
Good
Regular
Bad


Options

 Printer Friendly Printer Friendly

 Send to a Friend Send to a Friend


Please take a second and vote for this article.
Web site powered by PHP-Nuke

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest © 2003 by AnOldMan.com
PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.06 Seconds