jueves, 13 septiembre 2007
Viewing and storing images from an IP Camera
So you bought an IP camera and would like to store/see images from the camera using java. Recently I bought a couple of IP Cameras for testing purposes. I noticed that each IP camera has different surveillance tools and web interfaces. But most of them have in common that you can access the actual picture by entering an url in your browser.
In this post I'll show you how to see that image and store it using a very simple jav application. The camera I'll use for the test is a LinkSys WVC200 "Wireless PTZ Internet Camera with Audio". This is the cheapest wireless IPcam I found with at least
some decent features.

This camera has a nice web interface but for visualization purposes you will need to be sitting in front of a windows desktop. This camera as many others uses an activeX control to show/control the image. The thing is that LinkSys is kind enough to offer the camera's Firmware source code.
If you analyze the source code you can find some clues to get the URL where the static image is served (there's an url for video too ASF format, with some time you can develop an app to store and play the video). In the case of this camera is "http://CAMERAIP/img/snapshot.cgi?size=640x480".
With this information we can build an application to grab the image and show/store the image. If you have another type of camera, you can adapt the program by specifying the url.
>try {
/* Build a new URL specifying the path to where the image
* is served */
URL url = new URL ("http://192.168.10.80/img/snapshot.cgi?size=640x480");
/*String with the user and password to access the camera interface
*(userName and password that you would enter in the browser*/
String userPassword = "USER:PASSWORD";
/* We must encode with Base64 to supply it with the header.*/
String encoding = new Base64Encoder(userPassword).processString();
/*Open the connection*/
URLConnection uc = url.openConnection();
/* Specify the authorization*/
uc.setRequestProperty ("Authorization", "Basic " + encoding);
/* Load a copy of the image into memmory */
BufferedImage img = ImageIO.read(uc.getInputStream());
/* Show the image in a JLabel */
jLImagen.setIcon(new ImageIcon(img));
/* Store the image in the specified path*/
ImageIO.write(img, "jpg", new File("pathToFile"));
} catch (MalformedURLException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
Extending this simple application or adding some functionality can bring a very good surveillance application. If you analyze most commercial surveillance applications to use with different ipCameras you'll notice that although they are very expensive the core of the application is similar to the 10 lines of code above.
Technorati Tags: Linksys J2SE IPCamera PTZ WVC200 java JLabel ImageIO jpg wireless IPCam Camera webcam surveillance
Posted by at 12:19 PM in Java