What should I do/change/add in my code so my source would be my IP Cam?

4 views (last 30 days)
I have a code wherein my laptop camera would be the source of the video stream. It has a snapshot function once it runs, and the image captured will be saved in a specific folder.
However, I now want to use an IP cam as the source. The IP cam will be accessed through a router (an access point).
What should I add/change on my code and where should I place it (the additional code/change in the code)? The address of my IP cam is 192.168.0.101 at port 80.
I really hope somebody can help me :(
Here's the whole code by the way:
vid = videoinput('winvideo', 1, 'RGB24_640x480');
preview(vid);
pathname = 'C:\Users\Valued User\Documents\5th year, 2nd term\THESIS\imagesss';
if ~exist(pathname, 'dir')
mkdir(pathname);
end
for i=1
data= getsnapshot(vid);
pause(1);
imshow(data);
baseFileName = sprintf('ForDetection.jpg', 1);
fullFileName = fullfile(pathname, baseFileName);
imwrite(data,fullFileName);
end

Answers (2)

Haiko
Haiko on 16 Jan 2014
Edited: Walter Roberson on 16 Jan 2014
When using an IP-cam it works a bit different. To read a single image something similar as the following line of code can be used, assuming the IP camera uses MJPEG (motion jpeg). In this code the user name is 'admin' and the user password is 'admin' aswell.
Image = imread('http://192.168.0.101/snapshot.cgi?user=admin&pwd=admin');
When multiple pictures are required use a while or for loop.
For i=1:100
Image(i) = imread('http://192.168.0.101/snapshot.cgi?user=admin&pwd=admin');
end
good luck
  3 Comments
Haiko
Haiko on 16 Jan 2014
If you just need the one image, that would probably work. Note; part of the string 'snapshot.cgi?user=admin&pwd=admin' might be different, this depends a on your camera.
Walter Roberson
Walter Roberson on 16 Jan 2014
You would replace most of the code, not just add that at the top.
data = imread('http://192.168.0.101/snapshot.cgi?user=admin&pwd=admin');
baseFileName = sprintf('ForDetection.jpg', 1);
fullFileName = fullfile(pathname, baseFileName);
imwrite(data, fullFileName);

Sign in to comment.


John Alric
John Alric on 18 Jan 2014
I manged to get the feed from the IP Cam using this code
url = 'http://ce4563.myfoscam.org:88/snapshot.cgi?user=guest&pwd=1234';
ss = imread(url);
FileNum = 1;
fh = image(ss);
while(1)
pause(1)
ss = imread(url);
set(fh,'CData',ss);
drawnow;
FileNum = FileNum + 1;
end
But the frame rate is slower than the browser stream is there anyway to speed up the video?

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!