Undefined function 'snapshot' for input arguments of type 'char'.
9 views (last 30 days)
Show older comments
Niculai Traian
on 5 Mar 2019
Commented: Niculai Traian
on 5 Mar 2019
Hello, i am building a neural network and i am trying to use my phone camera for object classification. To do this i installed ip webcam to start a live stream and from matlab i acces the stream. The problem is it work if i dont try to use it for classification. But if i add the lines for classification it gives me this error: "Undefined function 'snapshot' for input arguments of type 'char'."
*i have to mantion that if i use laptop camera it works with no problems. Here is the code for classification and acces the live stream
url = ('http://192.168.1.2:8080/shot.jpg');
framesAcquired = 0;
%camera = webcam; % Connect to the camera
net = Net; % Load the neural net
h = figure;
h.Position(3) = 2*h.Position(3);
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
ax2.ActivePositionProperty = 'position';
while ishandle(h)
im = snapshot(url);
image(im)
im = imresize(im,[227,227]);
[label,score] = classify(net,im);
title({char(label), num2str(max(score),2)});
drawnow
% Select the top five predictions
[~,idx] = sort(score,'descend');
idx = idx(5:-1:1);
classes = net.Layers(end).Classes;
scoreTop = score(idx);
classNamesTop = string(classes(idx));
% Plot the histogram
barh(ax2,scoreTop)
title(ax2,'Top 5')
xlabel(ax2,'Probability')
xlim(ax2,[0 1])
yticklabels(ax2,classNamesTop)
ax2.YAxisLocation = 'right';
drawnow
end
0 Comments
Accepted Answer
Steven Lord
on 5 Mar 2019
The documentation lists 47 hits for functions with "snapshot" in the name (or perhaps just on their documentation page) in MathWorks products (including hardware support packages.) I haven't read through all of them but the ones I checked each expect as the first (in many cases only required) input an object representing the interface to the hardware from which you want to capture the image. You're not passing an object, you're passing a char vector.
I suspect you need to create the object to interface with your camera and call snapshot on that object rather than calling it with a URL. Alternately, if you have a function named snapshot that accepts just a URL and captures the image from that, can you post a link to the documentation for that function? Perhaps it's in a MathWorks product that is not present in your installation or one from a third-party that you haven't downloaded and installed.
3 Comments
Steven Lord
on 5 Mar 2019
No, the "Acquire One Image Frame from an IP Camera" example creates an ipcam object using the URL (on the first line of the example) and calls snapshot with that object as input (the fourth line of that example.) It doesn't call snapshot using the URL directly.
The "Acquire One Image Frame and the Timestamp from an IP Camera" example does the same thing (create an ipcam object and call snapshot on that object) on the first and second lines respectively.
You might want to use this documentation example as a model if your phone is an Android phone. This Deep Learning Toolbox example may also be of interest to you, though from code similarity I suspect you already knew about it.
More Answers (0)
See Also
Categories
Find more on Image Data Workflows 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!