Frame will not update with Live Video Tacking
Show older comments
Hello Everyone! I need some help... I'm working on a project that will track the position of a particle using a live video feed and frame capture. To start I created a custom GUI with the help of this tutorial:
I then added to the captureImage_Callback function to perform some image processing techniques and a for loop to capture 10 frames.
The issue that I am having now is that when I press the pushbutton "captureImage" The program does indeed capture 10 frames. However it is capturing the same frame 10 times. Is there a way I can have MATLAB update the frame to be captured so that I have subsequent frames instead of the same frame 10 times?
I apologize with my lack of experience with custom GUI's. I haven't done much work with them. attached is my code.
Thank you in advance!
Accepted Answer
More Answers (1)
John
on 15 Sep 2014
1 Comment
Geoff Hayes
on 16 Sep 2014
Hi John - you can take a look at the documentation at TimerFcn as this will be the property of the videoinput that you will need to modify in order to capture the ten frames (etc.). Unfortunately, there is very little to read, but the key point is the data type for the TimerFcn which is one of a string, function handle, or cell array.
In your code, you are using a string as
set(handles.video,'TimerPeriod', 0.05, ...
'TimerFcn',['if(~isempty(gco)),'...
'handles=guidata(gcf);'...
'image(getsnapshot(handles.video));'...
'set(handles.cameraAxes,''ytick'',[],''xtick'',[]),'...
'else '...
'delete(imaqfind);'...
'delete(hObject);'...
'end']);
You should be able to change it to a function handle as
set(handles.video,'TimerPeriod', 0.05, ...
'TimerFcn', @myTimerCallback);
Now, define the the callback as
function myTimerCallback()
if(~isempty(gco))
handles=guidata(gcf);
image(getsnapshot(handles.video));
set(handles.cameraAxes,'ytick',[],'xtick',[])
else
delete(imaqfind);
delete(hObject);
end
Try just changing the above (in your code) and re-run to ensure that the same behaviour still exists. Hopefully it will! Then you can make changes to myTimerCallback to check to see if the user has pressed the capture button, and if so, whether to continue writing frames to file. See guidata on how you can pass data from one callback to another (in your case, this may be to pass the "capture" button has been pressed from the capture button callback to the timer callback.
Categories
Find more on Image Preview and Device Configuration in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!