Thread Subject: "Internet" cameras

Subject: "Internet" cameras

From: Joel

Date: 15 Aug, 2007 15:54:07

Message: 1 of 12

I use the Image Aqu toolbox with standard webcams now.
Looking into buying a wireless camera to replace it but it
seems like these work a little differently. They have an
IP address on a local wireless network and you use your
webbrowser to view their images. They do not
have "driver software".

Can I use the image aquistion toolbox with these products?

Here is an example, but I am not married to this model.
http://www.dlink.com/products/?sec=0&pid=365

Subject: "Internet" cameras

From: Mark Jones

Date: 17 Aug, 2007 13:44:41

Message: 2 of 12

Joel wrote:
> I use the Image Aqu toolbox with standard webcams now.
> Looking into buying a wireless camera to replace it but it
> seems like these work a little differently. They have an
> IP address on a local wireless network and you use your
> webbrowser to view their images. They do not
> have "driver software".
>
> Can I use the image aquistion toolbox with these products?
>
> Here is an example, but I am not married to this model.
> http://www.dlink.com/products/?sec=0&pid=365

Hi Joel,

Currently we do not support these types of cameras because they are only
usable through a web browser.

Mark

Subject: "Internet" cameras

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 17 Aug, 2007 18:48:04

Message: 3 of 12

In article <46C5A649.2000705@mathworks.com>,
Mark Jones <mark.jones@mathworks.com> wrote:
>Joel wrote:
>> I use the Image Aqu toolbox with standard webcams now.
>> Looking into buying a wireless camera to replace it but it
>> seems like these work a little differently. They have an
>> IP address on a local wireless network and you use your
>> webbrowser to view their images.

>Currently we do not support these types of cameras because they are only
>usable through a web browser.

Perhaps urlread() could be used?
--
  There are some ideas so wrong that only a very intelligent person
  could believe in them. -- George Orwell

Subject: Web cam access in Matlab

From: Michele

Date: 22 Aug, 2007 00:24:08

Message: 4 of 12

roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fa4qh4$hli$1@canopus.cc.umanitoba.ca>...
> In article <46C5A649.2000705@mathworks.com>,
> Mark Jones <mark.jones@mathworks.com> wrote:
> >Joel wrote:
> >> I use the Image Aqu toolbox with standard webcams now.
> >> Looking into buying a wireless camera to replace it but it
> >> seems like these work a little differently. They have an
> >> IP address on a local wireless network and you use your
> >> webbrowser to view their images.
>
> >Currently we do not support these types of cameras
because they are only
> >usable through a web browser.
>
> Perhaps urlread() could be used?

I'm working on this right now. If your web cam is not
password protected, this should be easy. For example, I
have a TrendNet IP-100W camera that doesn't require a
password. I can load its video into Matlab with the single
command:

img = imread ('http://192.168.0.100/image.jpg') ;

The camera server stores the current frame in a file called
"image.jpg". Your camera might be different. Just connect
to it from a browesr and then view the page source - it
should be in there.

My problem is getting Matlab to do the WWW authentication
properly. The TrendNet cameras use Basic authentication. I
can easily do the Base 64 encode of the user name and the
password. Unfortunately, for me this ends with an "=" sign.
 For some reason, Matlab insists on writing this out on the
wire as "%3D" (ie. the 3 separate bytes 25 33 44) instead of
the single byte 3D (which is hex for "="). The camera then
gives me a password error.

Here's my code:

opt{1} = {'Authentication: Basic'}
opt{2} = {base64encode ('username:password')}
urlread ('http://192.168.0.101', 'POST', opt)

This is in R6 v.13 on a PC with XP if that matters.

I'm stuck. How can I get urlread to write "=" out as one
byte, 3D? Any help would be appreciated. Thanks!



Subject: Web cam access in Matlab

From: Matthew Simoneau

Date: 22 Aug, 2007 19:28:28

Message: 5 of 12

I took a quick look at URLREAD. In R2007a, line 85 looks
like this:

  value = char(java.net.URLEncoder.encode(params{i+1}))

I think this is where your "=" is becoming "%3D". This is
because these values are being passed as part of a form
submit, and not a header.

I think these threads will get you pointed in the right
direction:

http://www.mathworks.com/matlabcentral/newsreader/view_thread/81924
http://www.mathworks.com/matlabcentral/newsreader/view_thread/85012
http://www.mathworks.com/matlabcentral/newsreader/view_thread/52859

Subject: Web cam access in Matlab

From: Michele

Date: 24 Aug, 2007 00:15:05

Message: 6 of 12

"Matthew Simoneau" <matthew@mathworks.com> wrote in message
<fai2os$5pa$1@fred.mathworks.com>...
> I took a quick look at URLREAD. In R2007a, line 85 looks
> like this:
>
> value = char(java.net.URLEncoder.encode(params{i+1}))
>
> I think this is where your "=" is becoming "%3D". This is
> because these values are being passed as part of a form
> submit, and not a header.

Thanks very much, Matthew! We're halfway there. Your
analysis of the byte problem was correct. I modified
urlread by adding a urlConnection.setRequestProperty line
after the urlConnection = url.openConnection;. Now the
username:password combination gets written out properly and
it looks like the camera server accepts that.

Unfortunately, I still can't read my image. What's odd is
that, looking at the byte stream using Ethereal, it seems
like the camera is actually sending the requested image (I
see a TCP packet on the wire containing the string "Content
type: image/jpg", followed by lots of imagy-looking bytes)

But from this: imread ('http://192.168.0.103/image.jpg')
I get this:
??? Error using ==> imread
Unable to determine the file format.

If I say: urlread ('http://192.168.0.103/image.jpg')

I get

ans = yØÿâ

The imread does work just fine with a different camera (same
model) that doesn't require authentication.

I'm guessing that urlread isn't picking up the camera server
reply properly. Or maybe there's some funniness in imread??
 I'm going to work on this some more. In the meantime, if
anyone else has any ideas, I'd love to hear them. Thanks
for the help so far!

Subject: Web cam access in Matlab

From: Michele

Date: 24 Aug, 2007 00:56:02

Message: 7 of 12

OK, duh. I guess it helps to read the documentation. Right
at the start of urlread, it plainly says "If the server
returns binary data, the string will contain garbage." And
my camera is indeed returning my image, image.jpg, as binary
data.

So I guess my question now simply boils down to: how do I
read binary data from a server?

Subject: Web cam access in Matlab

From: Michele

Date: 24 Aug, 2007 20:31:59

Message: 8 of 12

Success! Turns out that urlread won't read binary data but
urlwrite will, and in fact imread calls urlwrite. So I just
applied the above authentication mod to urlwrite instead of
urlread. I can now read frames from my password-protected
Trendnet web cam. Code:

cam103 = imreadauth ('http://192.168.0.103/image.jpg') ;

"imreadauth" simply calls my modified version of urlwrite.

Note that a lot of other popular web cams (eg. D-Link) use
the same protocols, so this solution should work for them too.

In retrospect, I found the taxonomy of urlread/urlwrite
confusing. You've got urlread which reads urls as you might
expect. But urlwrite does not write urls - it just also
reads them and then saves them to a file. I submit that all
of this would be clearer and simpler if there was only one
function, urlread, with an optional file argument to save
the data to a file. Either that or let urlread work with
binary data the same way that urlwrite does. Right now, the
two functions seem to be slightly at odds with one another.

Subject: Web cam access in Matlab

From: Patrick

Date: 29 Jul, 2008 10:08:02

Message: 9 of 12

"Michele " <denber.nospam@mindspringNOSPAM.com> wrote in
message <fanf7v$h7f$1@fred.mathworks.com>...
> Success! Turns out that urlread won't read binary data but
> urlwrite will, and in fact imread calls urlwrite. So I just
> applied the above authentication mod to urlwrite instead of
> urlread. I can now read frames from my password-protected
> Trendnet web cam. Code:
>
> cam103 = imreadauth ('http://192.168.0.103/image.jpg') ;
>
> "imreadauth" simply calls my modified version of urlwrite.
>
> Note that a lot of other popular web cams (eg. D-Link) use
> the same protocols, so this solution should work for them too.
>
> In retrospect, I found the taxonomy of urlread/urlwrite
> confusing. You've got urlread which reads urls as you might
> expect. But urlwrite does not write urls - it just also
> reads them and then saves them to a file. I submit that all
> of this would be clearer and simpler if there was only one
> function, urlread, with an optional file argument to save
> the data to a file. Either that or let urlread work with
> binary data the same way that urlwrite does. Right now, the
> two functions seem to be slightly at odds with one another.


Hi,

I was wondering if you could list out the steps needed to
access the wireless IP camera. Seem to have missed some
steps in getting the images from the camera. Is there any
difference in the code for determining the code for a
password and non-password protected camera.

Thanks.

Subject: Web cam access in Matlab

From: Michele

Date: 29 Jul, 2008 17:19:01

Message: 10 of 12

> I was wondering if you could list out the steps needed to
> access the wireless IP camera. Seem to have missed some
> steps in getting the images from the camera. Is there any
> difference in the code for determining the code for a
> password and non-password protected camera.

OK, quick review: this applies to Trendnet webcams, models
100, 200, and 400, both the wired and wireless versions.
I've also tested it successfully with a DLink DCS-2000
webcam. It may work with other types too - I suspect all
these cameras use the same chip from some giant factory in
Malaysia.

If your camera is not password-protected, the job is easy.
The following line will grab one frame from the camera and
store it in a variable:

img = imread ('http://192.168.0.109/image.jpg') ;

(Obviously, you substitute the URL of your own camera there,
but the file name on the server is always "image.jpg")

If your camera requires a password, imread will not work
because there is no provision to supply one there. You need
to modify the urlwrite function to support the Basic
authentication these cameras use. You'd think that you want
to modify urlread but there's a confusing relationship
between imread, imwrite, urlread, and urlwrite. That's what
I was trying to untangle last year and you can read about it
in my previous posts. Anyway...

Step 1: Open up your copy of urlwrite and find the line that
says

urlConnection = url.openConnection;

Right after that, add this:

% The following line added as per
http://www.mathworks.com/matlabcentral/newsreader/view_thread/52859
urlConnection.setRequestProperty('Authorization','Basic xxx') ;

Save this modified imread as imreadauth.

(Thanks again to Matthew Simoneau for that wonderful piece
of code)

Step 2: Perform a Base64 encoding of your user name and
password and put the resulting string in place of "xxx"
above. I use:

pw = base64encode ('username:password') ;

Step 3: Modify your copy of imread to call imreadauth
instead of imread. Now, as I mentioned in my last post, you
can call

cam103 = imreadauth ('http://192.168.0.103/image.jpg') ;

This will log you in and retrieve the current frame to the
variable cam103.

Obviously, there's other ways of getting your username and
password in there, or having one function handle both
password and non-password webcams, but this is the gist of
it, and it works. Cheers.

Now if only I could get some kind soul to help me figure out
how to keep Matlab from hanging if the requested url is not
answering...



Subject: Web cam access in Matlab

From: Lynn

Date: 1 Oct, 2008 21:24:01

Message: 11 of 12

I was wondering if anyone else had attempted to adapt this to AXIS webcams (207MW). I am having difficulty and was hoping to get a real-time image through matlab to do some image processing. If you have any advice it would be appreciated.


"Michele " <denber.nospam@mindspringNOSPAM.com> wrote in message <g6nje5$m9a$1@fred.mathworks.com>...
> > I was wondering if you could list out the steps needed to
> > access the wireless IP camera. Seem to have missed some
> > steps in getting the images from the camera. Is there any
> > difference in the code for determining the code for a
> > password and non-password protected camera.
>
> OK, quick review: this applies to Trendnet webcams, models
> 100, 200, and 400, both the wired and wireless versions.
> I've also tested it successfully with a DLink DCS-2000
> webcam. It may work with other types too - I suspect all
> these cameras use the same chip from some giant factory in
> Malaysia.
>
> If your camera is not password-protected, the job is easy.
> The following line will grab one frame from the camera and
> store it in a variable:
>
> img = imread ('http://192.168.0.109/image.jpg') ;
>
> (Obviously, you substitute the URL of your own camera there,
> but the file name on the server is always "image.jpg")
>
> If your camera requires a password, imread will not work
> because there is no provision to supply one there. You need
> to modify the urlwrite function to support the Basic
> authentication these cameras use. You'd think that you want
> to modify urlread but there's a confusing relationship
> between imread, imwrite, urlread, and urlwrite. That's what
> I was trying to untangle last year and you can read about it
> in my previous posts. Anyway...
>
> Step 1: Open up your copy of urlwrite and find the line that
> says
>
> urlConnection = url.openConnection;
>
> Right after that, add this:
>
> % The following line added as per
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/52859
> urlConnection.setRequestProperty('Authorization','Basic xxx') ;
>
> Save this modified imread as imreadauth.
>
> (Thanks again to Matthew Simoneau for that wonderful piece
> of code)
>
> Step 2: Perform a Base64 encoding of your user name and
> password and put the resulting string in place of "xxx"
> above. I use:
>
> pw = base64encode ('username:password') ;
>
> Step 3: Modify your copy of imread to call imreadauth
> instead of imread. Now, as I mentioned in my last post, you
> can call
>
> cam103 = imreadauth ('http://192.168.0.103/image.jpg') ;
>
> This will log you in and retrieve the current frame to the
> variable cam103.
>
> Obviously, there's other ways of getting your username and
> password in there, or having one function handle both
> password and non-password webcams, but this is the gist of
> it, and it works. Cheers.
>
> Now if only I could get some kind soul to help me figure out
> how to keep Matlab from hanging if the requested url is not
> answering...
>
>
>

Subject: "Internet" cameras

From: Md. wahid

Date: 21 Sep, 2009 17:37:20

Message: 12 of 12

"Joel " <esposito@usna.edu> wrote in message <f9v7iv$76g$1@fred.mathworks.com>...
> I use the Image Aqu toolbox with standard webcams now.
> Looking into buying a wireless camera to replace it but it
> seems like these work a little differently. They have an
> IP address on a local wireless network and you use your
> webbrowser to view their images. They do not
> have "driver software".
>
> Can I use the image aquistion toolbox with these products?
>
> Here is an example, but I am not married to this model.
> http://www.dlink.com/products/?sec=0&pid=365
can u pls be more specific? i still got the error!

>> s= imread_b('http://192.168.2.100/image.jpg');
??? Error using ==> imread_b at 307
Can't read URL "http://192.168.2.100/image.jpg".

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
image aquisition Fabiano Santos 9 Jan, 2009 16:27:53
dicom format Michael Habib 14 Jun, 2008 07:13:15
urlwrite Michele 24 Aug, 2007 16:35:06
binary data Michele 23 Aug, 2007 21:00:21
imread Michele 23 Aug, 2007 20:20:23
web cam Michele 23 Aug, 2007 20:20:22
internet Michele 23 Aug, 2007 20:20:22
server Michele 21 Aug, 2007 20:25:23
authentication Michele 21 Aug, 2007 20:25:23
password Michele 21 Aug, 2007 20:25:23
urlread Michele 21 Aug, 2007 20:25:23
wireless Joel 15 Aug, 2007 11:55:05
web camera Joel 15 Aug, 2007 11:55:05
image aquisition Joel 15 Aug, 2007 11:55:05
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com