Clear Filters
Clear Filters

Undefined function 'snapshot' for input arguments of type 'double' why this error?

4 views (last 30 days)
This error is showin today and yesterday wasn't! i'm creating a webcam object, settings its parameters and taking a snapshot but today seems not working, this error keeps showin. " Undefined function 'snapshot' for input arguments of type 'double' "
clear('vid');
vid=webcam('USB Camera');
vid.Resolution='2048x1536';
vid.WhiteBalanceMode='manual';
vid.ExposureMode='manual';
vid.Exposure=-5.7;
vid.Gain=0;
vid.Hue=0; %-40 40
vid.Gamma=72; %72-500
vid.Contrast=64;
vid.Saturation=35;
vid.Sharpness=1;
vid.Brightness=15; %-64 64
vid.WhiteBalance=6500; %2800-6500
vid.BacklightCompensation=2; %0-2
im=snapshot(vid);
  1 Comment
mack cartagena
mack cartagena on 1 Jun 2018
i forget to say is running on a GUI and it seems to be a problem between functions, with one button i create the vid object as global then with another push button i'm taking the pictures but when i check just before the snapshot seems that de vid object is empty: vid=[] i solved it putin the creation of the vid object and the snapshot in the same push button function and it works, but now i have another problem. i don't want the GUI to create a vid object everytime i want to take a snapshot so i created a if condition to check if the vid object is already created and it works the first time i run the code and press the push button, but when i click again to take another picture the same erros shows up " Undefined function 'snapshot' for input arguments of type 'double' ", is like the vid object is deleted after the execution of the function. can some anyone help me :D
if exist==0
clear('vid');
maxAttempts = 30;
attempt = 1;
hasProperty = false;
while attempt < maxAttempts
vid = webcam('USB Camera');
hasProperty = max(ismember(properties(vid), 'Exposure'));
if hasProperty
% We got all the properties so we can quit trying.
fprintf('We have all camera properties after %d attempts. Now continuing with program.\n', attempt);
break;
end
fprintf('We do not have all camera properties after %d attempts. Trying again.\n', attempt);
attempt = attempt + 1;
clear('vid');
end
%CONFIGURACION PARAMETROS DE LA CAMARA
vid.Resolution='2048x1536';
vid.WhiteBalanceMode='manual';
vid.ExposureMode='manual';
vid.Exposure=-5.7;
vid.Gain=0;
vid.Hue=0; %-40 40
vid.Gamma=72; %72-500
vid.Contrast=64;
vid.Saturation=35;
vid.Sharpness=1;
vid.Brightness=15; %-64 64
vid.WhiteBalance=6500; %2800-6500
vid.BacklightCompensation=2; %0-2
assignin('base','vid',vid);
exist=1;
end
imagen=snapshot(vid);

Sign in to comment.

Answers (2)

Steven Lord
Steven Lord on 1 Jun 2018
Immediately before calling snapshot, check the class of the variable vid. My guess is that between when it was defined as a webcam object and when you tried to use it as a webcam object it got overwritten.
  1 Comment
Steven Lord
Steven Lord on 1 Jun 2018
The fact that this occurs in a GUI is important information.
If you've written the GUI code yourself or if you used GUIDE to implement your GUI, see this documentation page for some recommended ways to create data in one callback and share it with other callbacks.
Note that the word "global" does not appear on that page. That's intentional. You should avoid using global variables. You should also avoid creating variables in the base workspace. Using either global variables/the global workspace or the base workspace gives anyone who has access to those two workspaces the ability to affect / control your GUI.
If you've written the GUI using App Designer, see this page.

Sign in to comment.


Deepak Metta
Deepak Metta on 13 Jan 2020
Hey mack,
This maybe because of the cameraObject you're giving as input in the form of 'vid' to snapshot function is empty. There maybe problem with detecting your webcam.
Try running "webcamlist" in command window and notice the USB camera name which you've connected. Copy that and assign it vid then modify its properties. If it's not showing any webcam items in that array output then it may be the issue with detecting your webcam.
Make sure your MATLAB has USB support packages installed.

Categories

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

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!