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.
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!