我正在尝试使用2个视图和2个按钮在Matlab中创建GUI。 在第一个视图中,我想要实时显示从网络摄像头捕获的视频,在第二个视图中,我想在按下“捕获图像”按钮时显示第一个视图的视频屏幕截图。
问题在于,当我按下“拍摄图像”按钮时,视频和屏幕截图会切换它们的位置。我想在第二个视图中截图。
这是我的代码:
% --- Executes on button press in startStopCamera.
function startStopCamera_Callback(~, ~, handles)
% hObject handle to startStopCamera (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Start/Stop Camera
if strcmp(get(handles.startStopCamera,'String'),'Start Camera')
% Camera is off. Change button string and start camera.
set(handles.startStopCamera,'String','Stop Camera')
axesHandle= findobj(gcf,'Tag','VideoCapture');
preview(axesHandle, handles.video);
start(handles.video)
set(handles.captureImage,'Enable','on');
% Update handles structure
guidata(hObject, handles);
else
% Camera is on. Stop camera and change button string.
set(handles.startStopCamera,'String','Start Camera')
% axes(handles.VideoCapture);
stop(handles.video)
set(handles.captureImage,'Enable','off');
end
end
% --- Executes on button press in captureImage.
function captureImage_Callback(~, ~, handles)
% hObject handle to captureImage (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axesHandle= findobj(gcf,'Tag','Screenshot');
frame = getsnapshot(handles.video);
%frame = get(get(handles.Screenshot,'children'),'cdata'); % The current displayed frame
preview(axesHandle, frame);
end