Callback function is not executed anymore after using snapshot or step getting image frames
3 views (last 30 days)
Show older comments
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?
2 Comments
Image Analyst
on 26 Jun 2012
Does the button move at all when you press it? Or change color or get a little dotted line in it?
Accepted Answer
tlawren
on 26 Jun 2012
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 Comments
Image Analyst
on 27 Jun 2012
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.
More Answers (0)
See Also
Categories
Find more on Acquisition Using Any Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!