Archive for the 'Software' category

Time Lapse From CCTV

May 19 2007 Published by Eli under News,Software

Before heading home from work I always check the Washington State Department of Transportation traffic cameras. They give a good indication of how long I can expect to wade through traffic.

I started wondering how it would look in time lapse. This evening I wrote a Perl script to download and rename the CCTV images. Then I stitched a few hours worth together into an animated gif. The image below links to the animation. Beware, the image is almost 5MB.

Here’s my Perl script:
[code lang="perl"]

#/usr/bin/perl

use strict;
use Image::Grab;

my $url="http://images.wsdot.wa.gov/nwflow/cctv532.jpg";
my $timeout = 180;
my $filepath = "./";
my $filename = "cctv520-";
my $countplacement;
my $fileext = "jpg";
my $pic = new Image::Grab;
my $count = 1;

while ()
{
print "Downloading image...\n";
$pic->url($url);
$pic->grab;

if ($count >= 1000) { $countplacement = ""; }
if ($count < 1000) {$countplacement = "0"; }
if ($count < 100) { $countplacement = "00"; }
if ($count < 10) { $countplacement = "000"; }

print "Saving image: $filepath$filename$countplacement$count.$fileext\n";
open(IMAGE, ">$filepath$filename$countplacement$count.$fileext") || die "$filename.$fileext: $!";
binmode IMAGE;
print IMAGE $pic->image;
close IMAGE;

$count = $count + 1;

print "Sleeping for $timeout seconds\n";

sleep($timeout);
}
[/code]
It’s pretty simple, but it works. The Image::Grab Perl Module was really straight-forward.

No responses yet