Working with WPF and an IP camera

So I picked up a cheap tilt/pan, wireless IP camera (by Hootoo). If you’re not familiar, these just plug into the network (and then later can work wirelessly), and there is a built-in web server. From the browser interface, you can pan and tilt, and change settings, etc. For example:

image

The significance of an IP camera is that the video stream, controls, and still images are available via URL-like commands. For example, here are some things you can do:

http://192.168.1.126/snapshot.cgi?user=admin&pwd=thepassword
This generates a snapshot using all the current camera settings

http://192.168.1.126/videostream.cgi?user=admin&pwd=thepassword
This is an MJPEG video stream that you might stream to a player that supports that video type.

http://192.168.1.126/videostream.asf?user=admin&pwd=thepassword
This is an ASF video stream that you might stream to a player that supports that video type.

http://192.168.1.126/decoder_control.cgi?user=admin&pwd=thepassword&command=31
This is a tilt/pan camera – and this command tells it go to "position 1"

http://192.168.1.126/decoder_control.cgi?user=admin&pwd=thepassword&command=33
This is a tilt/pan camera – and this command tells it go to "position 2"

If you are using one of these Hootoo cameras, which are available everywhere – here is the API documentation (this took some time to find): http://www.drivehq.com/file/df.aspx/publish/bubbah/PublicFolder/IPCAMCGISDKV1.7.pdf

From the programming perspective:
My thinking was that I could add this to my little WPF status app. So while I’m in my office, I can see when someone pulls in the driveway, for example. Now, pulling snapshots and changing camera position were easy via this web API. Dealing with these streams has been a mess though. The MJPEG stream, I can’t seem to get anything working with. The ASF stream works in Windows Media Player, but still prompts me for credentials. Meanwhile, in WPF – the MediaElement doesn’t work with either. I spent some time researching, but ultimately didn’t find anything helpful.

So, for my purposes, I am ok with just doing periodic screen refreshes. So, I created a little ViewModel and update the image snapshot like twice per second, and bind an image to it. That should work! Well, it kind of does. The problem is that it takes the Image element some time to reload an image. This means that the picture "flickers" as it’s getting reloaded. My first thought was that the image control should have a "double-buffer" feature, but it doesn’t appear to. So, I hacked together a double-buffer to give me a better framerate.

Even that ended up not working well because sometimes I could get around 4fps while other times, I would "flip" between images ever 3 seconds, and the back image still wasn’t loaded yet. Put another way, I don’t to base this on a race-condition, and I couldn’t get any sort of reliable/flicker-free results from this approach.

So, I’ll continue to play around with this. The ultimate answer would just to be to use one of the streaming formats, because that’s a smooth 10-20fps ( I believe). So, I guess I need to figure out how to get that working with WPF.  To be continued…

Tagged with: , , , ,
Posted in .NET 4.0, Computers and Internet, New Technology, Uncategorized, WPF and MVVM
8 comments on “Working with WPF and an IP camera
  1. Bruce says:

    I have a couple of the same cameras and am using the snapshot http line embedded in a web page. Half the time though there is no image available when I load the web page so I have to manually enter the http line in the browser and refresh until I get an image. Curious if you have observed the same phenomenon.

    Like

  2. Rob Seder says:

    @Bruce – well first, this camera just stops working about once a day or so. No reason at all. I have to power cycle it to come back. Next, when I did try to snapshot.cgi – I did run into the same thing. Many of those snapshots were now valid images.

    As I understand it, this is a generic version of the Foscam IP cameras. My thought was to get a legitimate camera and see if acts any better. My ultimate end-state would be to use the videostream anyhow and I wonder if that works any better on a foscam?

    Like

    • Bruce says:

      Rob –
      Glad to hear you have noticed the same problem with snapshot.cgi. I will say that I have not had any need to reboot them daily; in fact I use them to remotely monitor a house 1000 miles away, where they are plugged in all the time. I too wonder if the Foscam brand works any better…guess I’ll buy one and see.

      Like

    • Bruce says:

      Have found a “trick” to keep the snapshot.cgi image alive – by enabling the image alarm function (even if email or FTP alarm response is not enabled) this keeps the camera active so that embedded snapshot images don’t show up as blank in the web page.

      Like

  3. Rob Seder says:

    Nice – thanks Bruce!!

    Like

  4. James says:

    You can use AForge to play the videostream.cgi with a decent frame rate, but no audio obviously.
    If you want to use the ASF stream with audio you can use the videolan vlc activeX control, but I think you need vlc properly installed.

    Like

  5. David says:

    I just found your Blog after buying one of these cameras and doing research to ‘tap’ into the camera functionality (so to speak)! Thank you very much! You had all the answers I was looking for!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives
Categories

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 5 other followers

%d bloggers like this: