To feed other video sources or image sequences into MATLAB one can use these approaches.
The standard simple code for ALEXNET as presented by MATLAB.
% Copyright 2016 The MathWorks, Inc. clear camera = webcam; % Connect to the camera nnet = alexnet; % Load the neural net while true picture = camera.snapshot; % Take a picture picture = imresize(picture,[227,227]); % Resize the picture label = classify(nnet, picture); % Classify the picture image(picture); % Show the picture title(char(label)); % Show the label drawnow; end
To use an IPCAM use this:
camera = ipcam('http://192.168.???.??:??/live/0/mjpeg.jpg','user','password');
obviously adapted to what your IPCAM do.
or if you want to stream a video use
camera = vision.VideoFileReader('E:\Videos\M4V00042.mp4');
To use an image sequence as a movie
dinfo = dir('X:\camera images\home\X\imagelog'); for i = 3:13000 bla = fullfile('X:\camera images\home\X\imagelog',dinfo(i).name); picture = imread(bla); picture = imresize(picture,[227,227]); % Resize the picture label = classify(nnet, picture); if char(label) == "ferry" fprintf("%s\n",char(label)); end image(picture) title(char(label)); % Show the label drawnow; end
If you want to use googlenet, vgg16, or 19 instead of Alexnet, you need to adjust the picture size.
This seems to work for all pretrained MATLAB Neural Networks
nnet = alexnet; ||
nnet = googlenet; ||
nnet = vgg19; % ONE of these
%Extract the input size dimensions.
sz = nnet.Layers(1).InputSize
and use this
picture = imresize(picture,[sz(1),sz(2)]);
picture = imresize(picture,[227,227]); % Resize the picture
in above loop.