How do I make live two cameras in a GUI?
조회 수: 2 (최근 30일)
이전 댓글 표시
I want to make a GUI with two live cameras. But I only have an axes live, actually, it looks like two live cameras only in camB and camA is empty. Please help me solve this problem, thanks in advance.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/195047/image.png)
Here is my code
function varargout = dualcam(varargin)
% DUALCAM MATLAB code for dualcam.fig
% DUALCAM, by itself, creates a new DUALCAM or raises the existing
% singleton*.
%
% H = DUALCAM returns the handle to a new DUALCAM or the handle to
% the existing singleton*.
%
% DUALCAM('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DUALCAM.M with the given input arguments.
%
% DUALCAM('Property','Value',...) creates a new DUALCAM or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before dualcam_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to dualcam_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help dualcam
% Last Modified by GUIDE v2.5 01-Sep-2018 23:53:13
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @dualcam_OpeningFcn, ...
'gui_OutputFcn', @dualcam_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before dualcam is made visible.
function dualcam_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to dualcam (see VARARGIN)
% Choose default command line output for dualcam
handles.output = hObject;
handles.videoA = videoinput('winvideo',1);
handles.videoB = videoinput('winvideo',3);
set(handles.videoA,'TimerPeriod', 0.05, ...
'TimerFcn',['if(~isempty(gco)),'...
'handles=guidata(gcf);'... % Update handles
'image(getsnapshot(handles.videoA));'... % Get picture using GETSNAPSHOT and put it into axes using IMAGE
'set(handles.camA,''ytick'',[],''xtick'',[]),'... % Remove tickmarks and labels that are inserted when using IMAGE
'set(handles.axCamA,''ytick'',[],''xtick'',[]),'...
'else '...
'delete(imaqfind);'... % Clean up - delete any image acquisition objects
'end']);
triggerconfig(handles.videoA,'manual');
handles.videoA.FramesPerTrigger = Inf;
set(handles.videoB,'TimerPeriod', 0.05, ...
'TimerFcn',['if(~isempty(gco)),'...
'handles=guidata(gcf);'... % Update handles
'image(getsnapshot(handles.videoB));'... % Get picture using GETSNAPSHOT and put it into axes using IMAGE
'set(handles.camB,''ytick'',[],''xtick'',[]),'... % Remove tickmarks and labels that are inserted when using IMAGE
'set(handles.axCamB,''ytick'',[],''xtick'',[]),'...
'else '...
'delete(imaqfind);'... % Clean up - delete any image acquisition objects
'end']);
triggerconfig(handles.videoB,'manual');
handles.videoB.FramesPerTrigger = Inf; % Capture frames until we manually stop it
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes dualcam wait for user response (see UIRESUME)
uiwait(handles.dualcam);
% --- Outputs from this function are returned to the command line.
function varargout = dualcam_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in btnStart.
function btnStart_Callback(hObject, eventdata, handles)
% hObject handle to btnStart (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if strcmp(get(handles.btnStart,'String'),'Start')
% Camera is off. Change button string and start camera.
set(handles.btnStart,'String','Stop')
axes(handles.camA)
start(handles.videoA)
axes(handles.camB)
start(handles.videoB)
else
% Camera is on. Stop camera and change button string.
set(handles.btnStart,'String','Start')
stop(handles.videoA)
stop(handles.videoB)
end
% --- Executes when user attempts to close dualcam.
function dualcam_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to dualcam (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
delete(hObject);
delete(imaqfind);
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!