Nowadays, you can get IP cameras pretty cheap. If you are not familiar, an IP camera is sort of like a portable/mountable webcam, that has a built-in web server. The purpose being that you can set up this camera, and then view it by going to a certain address in your web browser – if you are connected to the same network.
You can find a bunch, new, which support tilt/pan for around $70-90 on Amazon.
Anyhow, I had something specific in-mind in terms of what I wanted for an user interface, for my cameras. The first step was figuring out how to access the video. I went down that road before and didn’t get very far because the video “stream” it produces was proprietary and not easily consumable. However, I don’t really need a stream – what about just getting snapshots? I just really want a few frames per second and that would be fine.
So, I found this PDF on the Foscam site which describes the web interface to get access to the stream – or in my case, the snapshot. That URL looks something like this:
From there, I used a System.Net.WebRequest to go get the snapshot – I take that stream and put it into a System.Drawing.Image object – and then assign that image to a PictureBox object I have on the screen. I have 4 cameras, so that looks something like this:
Updating the image:
I did some research here and the actual web request takes anywhere from 250ms (1/4 of a second) to 2-3 seconds. I couldn’t find a fix for this. So, as the code stands now, it tries to get a new image a few times per second, but it is not successful and/or it returns from multiple calls at the same time. You still end up with a picture, but there is a just a delay. So, for any given camera, I’ll see an update from twice per second – to an update every 2 seconds.
I also kick off the webrequest and update in another thread by using a Task object. In other words, all 4 cameras as off getting their updated images, while the UI isn’t slowed down or blocked at all during the updates.
Adding timestamp and camera name:
Once you have a .NET System.Drawing.Image object – you can simply create a Graphics object and do a .DrawString on there with the camera name and timestamp of the image:
Dealing with errors:
I chose to still show the timestamp and label – and then just show the exception inside of the image. I will likely change this later. This too, just uses a Graphics object to output text onto the image:
So there it is – a basic viewer for Foscam-style IP cameras. Now that I have basic functionality, I can finish fleshing out my application.