Callback function is not executed anymore after using snapshot or step getting image frames

3 次查看(过去 30 天)
I am using a GUI to start and stop my video camera. First I create the videoinput with
  • vid = videoinput('avtmatlabadaptor64_r2009b',1,'F7M0_Raw8_1032x778');
  • start(vid);
Everything works fine if I get image data in a loop data with:
image = getdata(vid,1,'single')
But this is extremely slow. So I changed this line into
image = getsnapshot(vid); (or alternatively into image = step(vid); using imaq.VideoDevice)
which both run 10 times faster. My problem is now that my GUI button press functions are not executed anymore when I press a button. The header of this function is: function buttonStop_Callback(hObject, ~, handles) Has anyone an idea how I can fix this problem?

采纳的回答

tlawren
tlawren 2012-6-26
What does your stop callback function actually do? Does it set a stop flag variable? When I make data collection GUIs, I typically put my data collection code inside a loop that is designed to run non-stop until a stop flag is set. My stop buttons then have only one purpose and that is to set the stop flag. A rough example of this process is the following.
% pre-collect data stuff
set(handles.StopButton,'UserData', 0);
while (get(handles.StopButton,'UserData') == 0)
% collect data
end
% post collect stuff
The StopButton function simply sets the UserData field in handles.StopButton to 1.
This may not be the best way to actually collect data in a GUI and it may not be of any use to you (I don't know how getdata and getsnapshot work), but it might be an idea to consider.
  4 个评论
Rainer Mautz
Rainer Mautz 2012-6-26
Not any of all my callback functions would break the while loop until I added a pause(0.01) within the loop. Now it works i.e. the callbacks are called, but it is unclear to me why.
Image Analyst
Image Analyst 2012-6-27
I'm not sure why either. All I know is that I've tried to do that before and it doesn't work with buttons, however it does work with checkboxes. So if I need to break out of an intensive, computationally heavy loop I make visible a checkbox that says "Finish now" which the user can click and my loop can check and bail out if it's checked. Then I hide the checkbox until the next time. Making a "Finish Now" button to set a "FinishNow" flag didn't seem to work, I guess because the loop was so intensive it never got around to starting that parallel code execution going. Maybe putting in that pause gave it a chance to catch its breath and do other things, like running that button's callback.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by