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

2 次查看(过去 30 天)
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

回答(2 个)

Haiko
Haiko 2014-1-16
编辑:Walter Roberson 2014-1-16
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 个评论
Haiko
Haiko 2014-1-16
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 2014-1-16
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);

请先登录,再进行评论。


John Alric
John Alric 2014-1-18
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?

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for IP Cameras 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by