필터 지우기
필터 지우기

I'm trying to use a toggle button to start and stop video acquisition but i get the following error. Could any1 help???

조회 수: 2 (최근 30일)
Trying to use a simple toggle button to start and stop my video processing i get an error.
my code under that of the toggle button being
% Hint: get(hObject,'Value') returns toggle state of startstop
clc;
source= videoinput('winvideo');
set(source, 'ReturnedColorSpace', 'RGB');
set(source, 'FramesPerTrigger', 1);
set(source, 'TriggerRepeat', inf);
triggerconfig(source, 'manual');
start(source);
pause(2);
trigger(source);
if get(handles.startstop,'Value')
set(handles.startstop,'String','Stop');
set(handles.startstop,'Value',1);
drawnow();
else
set(handles.startstop,'String','Start');
set(handles.startstop,'Value',0);
clear(source);
stop(source);
end
i get the following error
??? Error using ==> imaqdevice.start at 91
Multiple VIDEOINPUT objects cannot access the same device simultaneously.

채택된 답변

Walter Roberson
Walter Roberson 2013년 1월 26일
When you push the toggle button to start the video, you create the videoinput(). Then when you push the button to stop the video, you again create the videoinput.
When you have a togglebutton, the code does not somehow wait around for the togglebutton to change state and then continue. Instead each time you push the togglebutton, the entire callback is executed.
You need to find a way to save the value of "source" somewhere so it can be available for when you are turning off the video.
Note: clear() must be applied to a variable name, and after you clear the variable, it will no longer be in the workspace to be available to stop(). clear() does not stop a video object; see http://www.mathworks.com/help/imaq/clear.html, and it also does not delete the video object; see http://www.mathworks.com/help/imaq/delete.html. You should stop the object, and delete it. If it is a local variable then you do not need to clear it as the local reference will go out of scope when the function returns.
  댓글 수: 8
Sanjeev
Sanjeev 2013년 1월 27일
thanks Walter. ur code is working perfectly. if u dont mind could you explain what the codes u added does exactly??
handles.source = source;
guidata(gcbo, handles);
drawnow()
handles.source = [];
guidata(gcbo, handles

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by