Wednesday, October 10, 2007

Background to the "GRLevel3 Live Webcam Project"


I started the GRLevel3 Live Web Project (GR3LWCP) in late summer 2006. Ever since Placefiles were introduced to GRLevel3, I wanted to figure out some way to add web cam pictures on the radar screen, much like what is done on the web page "WeatherBonk". Once I felt I had a decent understanding of placefiles, I went to work.

Here is a list of the programs you'll need:

GRLevel3 (goes without saying)
URL2File
ImageMagick
Google Earth

URL2File is a free 32bit Windows console-mode application able to retrieve and save the content of a given World Wide Web or FTP URL to a local file. (quoted right from their web page). In other words, using a DOS window, you can type in some simple commands to grab the file you want and save it directly to your computer. This program is a very small file, less than 500K.

ImageMagick is a software suite to create, edit, and compose images. The functionality of ImageMagick is typically utilized from the command line or you can use the features from programs written in your favorite programming language. (quoted from their web page). This is a much larger download, about 15Mb.

Google Earth was used to find the lat/lon of the cameras' location.

Getting started!

The first thing I had to do was download URL2File and ImageMagick. I saved URL2File to my computer: C:\Program Files\GRLevelX\GRLevel3.

Next, I installed ImageMagick onto my computer (e.g. C:\Program Files\ImageMagick-6.2.9-Q16). (editor's note: this was the current version when I first started this project. It has since been updated!)

Next, I had to find the raw images to import. My search started here in Kansas, looking for web cams at TV stations, schools, etc. However, I didn't want to save the web page, just the raw image from the web cam (whatever format is used.) For example, there is a camera in Lawrence that I found at this site:

http://www.lawrence.com/downloads/webcams

In doing a little sniffing around, I found the raw image:

http://etc.lawrence.com/webcam/tower.cgi

This search went on and on until I found a decent amount of web cams.

Creating Files:

First we'll need a .bat file that will not only download/save the images, but also process them using ImageMagick into a format that GRLevel3 can use. I wrote webcam.bat and placed it a new folder where GRLevel3 is located. It is:

C:\Program Files\GRLevelX\GRLevel3\pictures

For instructional purposes, the original webcam.bat file looked something like this:

del *.jpg
del *.png

URL2File http://media.mgbg.com/kwch/images2/towercam/kwchtower.jpg kwch.jpg
URL2File http://media.49abcnews.com/img/webcam/axis0.jpg ktka.jpg
URL2File http://etc.lawrence.com/webcam/tower.cgi klwc.jpg

convert kwch.jpg -resize 120x90! kwch.png
convert ktka.jpg -resize 120x90! ktka.png
convert klwc.jpg -resize 120x90! klwc.png

convert kwch.png ktka.png klwc.png +append -matte webcam1.png

You'll notice that in this DOS-based script, I first delete all of the old images (jpg/png) in this folder, then start the download.

URL2File http://etc.lawrence.com/webcam/tower.cgi klwc.jpg

In this line for example, URL2File goes to the lawrence.com web site and downloads the picture, saving it as "klwc.jpg". After it downloads all of the new images, it then converts them using ImageMagick. For example:

convert klwc.jpg -resize 120x90! klwc.png

This line tells ImageMagick to convert klwc.jpg to a 120x90 .png file titled klwc.png.

The final line:

convert kwch.png ktka.png klwc.png +append -matte webcam1.png

...takes all of the new, resized .png files and in the order I programmed, arranges them from left to right, adds an alpha channel and saves it as webcam1.png. I don't want to bore you with a complete tutorial of ImageMagick. Heck, there's much more **I** need to learn. For more, please visit their web page.

Next, we'll need a placefile to display these web images. I created yet another folder (C:\Program Files\GRLevelX\GRLevel3\places) to put all of my custom placefiles in.

Here's what the very first web cam placefile looked like:

;gr3webcam.txt Verison 0.1
;Placefile for GRLevel3 by Rodney Price, 09/06/06
;updated 9/12/06
Refresh: 2
Title: KS/MO/OK Web cams
Threshold: 500

Color: 200 200 255

IconFile: 1, 120, 90, 60, 45,"C:\Program Files\GRLevelX\GRLevel3\pictures\webcam1.png"
Font: 1, 11, 1, "Arial"

Icon: 37.75093, -97.303882, 0,1,1, "KWCH Web Cam"
Icon: 39.027859, -95.748661, 0,1,2, "KTKA Web Cam"
Icon: 38.973357, -95.235810, 0,1,3, "Lawrence Web Cam"
End:

I created a shortcut on my desktop for webcam.bat. It's not an automatic script. I just run it periodically when I want to as GRLevel3 is up and running.

When everything is up and running, the picture at the top of the post is what it will look similar to.

I'm sure more advanced users could whip up something along the same lines using PHP for example. I just wanted to develop something simple that I could use without learning a new programming language! It's not the most extravagant placefile but maybe it can be of use to some folks.

One drawback to this approach: if one of the web cameras in the script is down, then all of the cameras immediately following it will be plotted in the wrong location. For example, if camera 2 is down, when the image from camera 3 loads, it will be plotted in the camera 2 location (and so on and so forth.)

IMPORTANT EDITOR'S NOTE: On any of the batch files ending with "bat.txt", be sure to change the name so that the extension is ".bat" instead. For example, ks1cambat.txt should be changed to ks1cam.bat. That way your computer knows it's a batch file and will run the program correctly.

ALSO! If you are running the scripts separately (instead of using "gr3cam.bat"), be sure to run ks1cam.bat first as it has the "del *.jpg" and "del *.png" commands at the top of the script. Or, simply delete those 2 lines of code out of the script. Your call.

No comments: