How to run webcam on an axis in app designer ?

22 views (last 30 days)
function startcamerabutton_Callback(app, event)
% hObject handle to startcamerabutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
app.camera=videoinput('winvideo',1);
imshow(app.camera,'Parent',app.livedisplay);
end
  1 Comment
Ahmer Shahid
Ahmer Shahid on 1 Nov 2018
This Error showing up there.......
Error using imageDisplayValidateParams Expected input number 1, I, to be one of these types:
numeric, logical
Instead its type was videoinput.
Error in images.internal.imageDisplayValidateParams (line 11) validateattributes(common_args.CData, {'numeric','logical'},...
Error in images.internal.imageDisplayParseInputs (line 78) common_args = images.internal.imageDisplayValidateParams(common_args);
Error in imshow (line 245) images.internal.imageDisplayParseInputs({'Parent','Border','Reduce'},preparsed_varargin{:});

Sign in to comment.

Accepted Answer

Astarag Chattopadhyay
Astarag Chattopadhyay on 20 Nov 2018
Edited: Astarag Chattopadhyay on 23 Nov 2018
Hi Ahmer,
You do not need to use "videoinput" object you can use "webcam" object.
In your app define two properties like this:
properties (Access = private)
webcamObject;
imageObject;
end
You can define the startup function using the following code snippet:
function startupFcn(app)
app.webcamObject = webcam;
app.imageObject = image(app.UIAxes);
axis(app.UIAxes,'ij')
res = split(app.webcamObject.Resolution,'x');
app.UIAxes.XLim = [0,str2double(res{1})];
app.UIAxes.YLim = [0,str2double(res{2})];
app.webcamObject.preview(app.imageObject);
end
This will setup the UIAxis with the resolution of the webcam object and start the preview.
  4 Comments
Astarag Chattopadhyay
Astarag Chattopadhyay on 4 Dec 2018
Which version of MATLAB you are working on?
If you want to take a snapshot you can add a snapshot button to the app and add a callback to the button where you may use the function "snapshot".
Ahmer Shahid
Ahmer Shahid on 4 Dec 2018
I'm using Matlab R2018a, I'm already working on that but when I use snapshot or getsnapshot then it give me error that snapshot is invalid function for webcam.
I can use snapshot function for videoinput but I cannot get the live streaming on axis while using videoinput.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!