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

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

Does the button move at all when you press it? Or change color or get a little dotted line in it?
yes the button (and others) on my GUI do move when I press them. Only the function behind is not called.

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

 채택된 답변

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

My callback function stops and deletes the video object. It reads:
stop(vid);
clear vid;
set(handles.buttonStart,'UserData',0);
guidata(hObject, handles);
disp('System stopped');
In fact it does change the UserData variable. But the point is that it doesn't jump in this function automatically. And there are more "buttons" on my GUI that have functions behind that are not called anymore. Your suggested workaround sounds good to me. I only need to know what happens when I press the button? What variable changes so that I can trigger the lines that you suggest?
My stop button callbacks typically look something like the following ...
function StopButton(hObject, ~, handles)
set(handles.StopButton,'UserData',1);
guidata(hObject, handles);
This will (should) break the *while* loop that contains the data collection code. I place all of my post data collection and clean up code after the while loop. This allows my stop buttons to have one function, and that is to set a variable to stop a data collection loop. Again, this may not be the best way to do things, but it works and it seems clean enough.
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.
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개)

질문:

2012년 6월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by