This is a simple web based surveillance system using OpenCV, PHP and Javascript. The system is designed to be low cost and simple, using only a webcam attached to a PC as the client. For the server side, you can use any regular web hosting.
The system itself is very simple. It saves an image taken from the webcam in an interval of time. The image then submitted to web server and displayed in a web page to browser. Some Javascript code will refresh the image without reloading the whole page in an interval of time.
Such a system provides a low cost remote surveillance system. No need to buy expensive cameras or web hosting service that supports video streaming.
The system follows the Client-Server model. The client is a PC with a webcam attached to it. This is where you want to monitor things. The server is a regular web hosting. You can view the "video stream" using any PC connected to the Internet. The block diagram is shown in Figure 1.

The are 4 parts of code, reside on the client and server side:
cam.c): Saves a frame to file in a specified interval of time.sender.php): A daemon to POST the saved frame to web server.recv.php): Save the submitted image to disk.index.html): Page to display the image, with Javascript to auto refresh the image.Just like the name, Frame Grabber grabs the frames from webcam and display the video. The full listing is shown below. It makes use OpenCV, an open source computer vision library from Intel.
Listing 1: Frame Grabber with Autosave
The code above display the video from webcam, and automatically save the frame to img.jpg every 3 seconds. The saved image then submitted to server by sender.php, described in the following section. I want to make things simple, so I choose PHP.
This is a daemon (background process) that waits for a new image from the Frame Grabber. Once the image arrive, the script will send the image over HTTP to the server.
Basically, sender.php simulates a HTML form like this:
<form action="http://nashruddin.com/surveillance/recv.php" method="post">
<input type="file" name="img" value="" />
<input type="submit" />
</form>
When the new image has come, it fills the value of <input type="file" /> with img.jpg, and push the submit button. the code is shown below.
Listing 2: Image Sender
The script checks for new images by comparing the file's modification time. If a new image found, it will POST the image by calling send_file function.
send_file() is my custom function to make HTTP POST request. Of course one can use Curl library, but since Curl is not always available on some systems, I think it would be better to make a custom function when portability comes into mind.
Listing 3: Function to POST a file
You must run the script sender.php as daemon (runs forever in the background), before you run the FrameGrabber. Simply type the command below in your console:
php sender.php &
Note: remove the '&' if you use Windows.
This part is very simple, it retrieves the submitted image and save it to disk.
Listing 4: Save the submitted file to disk
This page displays the image to browser. Some javascript code will refresh the image every 3 seconds without reloading the whole page.
Listing 5: HTML page with autorefresh
Nash on Mar 22, 2009:
Shiva on Mar 22, 2009:
Innocent on Apr 11, 2009:
Nash on Apr 13, 2009:
yalamber on Jun 17, 2009:
Nash on Jun 24, 2009:
Espen on Jan 15, 2010:
Paul on Apr 15, 2010:
Nash on Apr 16, 2010:
kishore on Apr 27, 2010:
Matt on Sep 4, 2010:
allankliu on Nov 26, 2010:
Mario on Dec 17, 2010:
| ICQ | 489571630 |
| Skype | dede_bl4ckheart |
| Yahoo | dede_bl4ckheart |
| nashruddin.amin |
Cheba on Mar 21, 2009:
How?
any idea?
I have only experience with EmguCV/C#.