Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Web cam access in Matlab
Date: Tue, 29 Jul 2008 17:19:01 +0000 (UTC)
Organization: Michele Denber (ID: 1-A7A3B)
Lines: 73
Message-ID: <g6nje5$m9a$1@fred.mathworks.com>
References: <f9v7iv$76g$1@fred.mathworks.com> <46C5A649.2000705@mathworks.com> <fa4qh4$hli$1@canopus.cc.umanitoba.ca> <fafvn8$q4$1@fred.mathworks.com> <fai2os$5pa$1@fred.mathworks.com> <fal7u9$m0r$1@fred.mathworks.com> <falab2$lve$1@fred.mathworks.com> <fanf7v$h7f$1@fred.mathworks.com> <g6mq62$dsh$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1217351941 22826 172.30.248.37 (29 Jul 2008 17:19:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 29 Jul 2008 17:19:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 174773
Xref: news.mathworks.com comp.soft-sys.matlab:482453



> 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...