How can I use the IMREAD function with a URL that requires basic authentication in MATLAB 2014a??? (not the old matlab)

3 views (last 30 days)
I want to access ip-camera images using imread , but due to authentication, it is unaccessable. so please help.

Answers (1)

Cairo L. Nascimento Jr.
Cairo L. Nascimento Jr. on 7 Mar 2015
Edited: Cairo L. Nascimento Jr. on 7 Mar 2015
I have tested the following solution in MATLAB R2013a and R2014b. I guess it should work in the MATLAB releases after R2013a.
1) For your specific IP camera model, find the HTTP/CGI command to grab the current camera image (snapshot) with basic authentication turned OFF.
Each camera manufacturer use a different command. You may have to search the manufacturer's website or use Google to find this information.
Some examples:
AXIS: http://{ip_address}:{port}/axis-cgi/jpg/image.cgi
LINKSYS: http://{ip_address}:{port}/img/snapshot.cgi
TRENDnet: http://{ip_address}:{port}/cgi/jpg/image.cgi
FOSCAM: http://{ip_address}:{port}/snapshot.cgi
Using your favorite web browser, acess your IP camera, turn authentication off and test the CGI command to get a snapshot of the camera. Then turn authentication on again.
2) In MATLAB:
a) firstly define the correct values for the variables: url, img_file, username, password. For instance:
% URL to get a camera snapshot
url='http://192.168.0.50/cgi/jpg/image.cgi';
img_file='image_cam.jpg'; % temporary file used to store the camera image
user='cam_user'; % username and password used to perform authentication
pass='cam_password';
b) execute the following MATLAB commands:
% grab the camera image and store it in a local temporary file
urlwrite(url,img_file,'Authentication','Basic','Username',user,'Password',pass);
% show the camera image and delete the local temporary file
imshow(imread(img_file));
delete(img_file);
I hope this info is useful.
Cairo L. Nascimento Jr. (<mailto:cairo@ita.br cairo@ita.br>)
ITA, Brazil

Categories

Find more on MATLAB Support Package for IP Cameras in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!