I am using MATLAB to process image files that are created by a camera and stored in a directory on Windows. I am trying to incorporate feedback into control of the camera and therefore require MATLAB to process an image every time a new image is created and appears in the directory. I have never created a MATLAB program that runs continuously and waits for an event to occur.
From what I've read online it appears my best option is to use a timer object and have the MATLAB program read the contents of the directory repeatedly. Is this a good approach or are there alternative approaches I can implement?
I'm wondering if there is a way the MATLAB program can be "triggered" by the appearance of a file in a directory as opposed to constantly surveying the contents of this directory. I hope there is because as the directory fills up I find that the "dir" command in MATLAB is really slow; slow enough that I may not be able to process images as fast as I require.
As a follow up. Are there any recommendations about how to deploy this program? An idea I like is a simple GUI with a "start" and "stop" button.
Thank you.
You could do the following:
Create timer object, which will check your directory every 10 seconds:
your 'mycallback' function should look something like this:
Now you need to start the timer object
You can stop the timer object with
The correct way to do this is to purchase the MATLAB Image Acquisition Toolbox (http://www.mathworks.com/products/imaq/). This functionality is intentionally not included in the base Matlab environment.
Alternatively, with some clever programming you could implement a work-around. The build-in MATLAB functions will likely be too slow. Your best bet would be to write the functionality you need in Java (See http://www.exampledepot.com/egs/java.io/GetFiles.html) and then calling your Java code directly from Matlab (see http://www.mathworks.com/help/techdoc/matlab_external/f44062.html).
Fundamentally, unless you are accessing the camera drivers or framegrabber directly, you will always need to implement some kind of directory polling.