Easy way to grab image from Axis IP Camera

I was supposed to develop a program in OpenCV which can capture image from Axis 207 IP Camera. So I was searching in google to find the normal way to capure image from Axis IP Camera. I found some solutions. Some people told that they used cvCreateFileCapture() or some other use Axis Media Controller SDK. I was trying to use those. Using cvCreateFileCapture() I got blank image and using Axis Media Controller SDK I got some error. But I was in hurry to solve this problem. Then I got an idea. You know that Axis IP camera has it's own web sever. In every 1 second it creates 20 image in it's web server. Then I was trying with "wget" command. But it didn't work. One my friend (Faruk Ahmed) remembered me a perl command which was normally used for downloading files. The perl command is "lwp-download". So I installed Perl in my System.



So from now you don't need to install any other driver to capture image from Axis IP Camera in any kind of system (Windows, Unix/Linux, Mac). Just install Perl and connect your camera. :-)

Here is a very simple OpenCV program to capture image from Axis IP Camera, convert it to grayscale and binary image in every 5 second.



/*
This simple program is written by Khandakar Mujahidul Islam.
Using this program someone can grab image from Axis IP Camera.
I used Axis 207 IP Camera.
*/

#include "stdio.h"
#include "tchar.h"

#include "cv.h"
#include "cxcore.h"
#include "highgui.h"


// A Simple Camera Capture Framework
int main() {

int time = 500;

for(int t=0;t
{
/*Removing Existing Image. "del" in Windows and "rm -f" in Linux*/
system("del image.jpg grayscale.jpg binary.jpg");

/*
Downloading Image from Axix Camera Image Server.
Camera IP = 169.254.195.48
*/
system("lwp-download http://169.254.195.48/jpg/image.jpg");

/*Loading Original Image*/
IplImage *originalImage  = cvLoadImage("image.jpg",-1);

/*Creating Blank 640x480 image; 8 means 8 bit unsigned image*/
IplImage * grayScaleImage = cvCreateImage(cvSize(640,480),8,1);
IplImage * binaryImage = cvCreateImage(cvSize(640,480),8,1);

/*
Give a name to Image Window.
Move the image window.
Show Image.
*/
cvNamedWindow("Original", 1);
cvMoveWindow("Original", 0,0);
cvShowImage("Original", originalImage);


/*
Creating Gray Scale Image.
Save the Image.
Give a name to Image Window.
Move the image window.
Show Image.
*/
cvCvtColor(originalImage, grayScaleImage, CV_BGR2GRAY);
cvSaveImage("grayscale.jpg",grayScaleImage);
cvNamedWindow("GrayScale", 1);
cvMoveWindow("GrayScale", 550,400);
cvShowImage("GrayScale", grayScaleImage);

/*
This is the Canny Edge Detector function
*/
/*
cvCanny(grayScaleImage, edgeImage, 0.5, 0.5, 3);
*/

/*
Creating Binary Image.
Save the Image.
Give a name to Image Window.
Move the image window.
Show Image.
*/
cvThreshold(grayScaleImage, binaryImage, 130, 255, CV_THRESH_BINARY);    
cvSaveImage("binary.jpg",binaryImage);
cvNamedWindow("Binary", 1);
cvMoveWindow("Binary", 650,0);
cvShowImage("Binary", binaryImage);

/*
Wait for 5 Sec (1 sec = 1000 mili sec)
*/
cvWaitKey(5000);

/*
Closing the Image Window
*/
cvDestroyWindow("Original");
cvDestroyWindow("GrayScale");
cvDestroyWindow("Binary");

/*
Releasing Image from Memory
*/
cvReleaseImage(&originalImage);
cvReleaseImage(&grayScaleImage);
cvReleaseImage(&binaryImage);
}

return 0;
}


Comments

Kaiser Sodrohu said…
Hello....

What are the include files that you use for this program?
Hello Kaiser,

Included header files are stdio.h, tchar.h, cv.h, cxcore.h and highgui.h.

I had put the header files within "<" and ">". But this blog does not show the file name if the name within arrow sign.
Kaiser Sodrohu said…
I've installed the perl, but still couldn't make it run. Is there any libs or include files that i need to put inside my project before it works?
No, you don't have to put any lib. After installing Perl try to install "lwp-download" in command prompt (Windows)/ Terminal (Linux). If this command work, then you are done.
Unknown said…
Hello Suzan
My name is Joe. I living in Thailand. I have some problem about connect IP camera with visual c++. My camera is BOSCH NWC-0900. Could you pleas help me?

joe
wirotep@hotmail.com
Unknown said…
This comment has been removed by the author.
Dear Joe,

Can you please elaborate what kind of problem your are facing with your camera?

Suzan
Q said…
Hi I receive this error

lwp... is not recognized as internal or external command! what's the problem? thx
Q said…
This comment has been removed by the author.
Q said…
This comment has been removed by the author.
Q said…
This comment has been removed by the author.
Q said…
This comment has been removed by the author.

Popular posts from this blog

Bengali in Google Transliteration