Real Time Functionality of Matlab -- I need Matlab to find an image file and open it once the image file is created.
Show older comments
I am doing a project which automates the capture of a webcam. I need matlab to check the image file repetitively until it finds it that is, matlab will able to find it only when the camera captures an image.
Here is my code for iteratively opening a file:
uint8 img;
img = 0;
while img == 0
img = imread('F:\pictures\irisgray1.png');
end
This code however has an error on this line [img = imread('F:\pictures\irisgray1.png');] because irisgray1.png is not yet created on the directory because the camera does not captures anything yet. I need to have a code that will check the file until it is created.
Accepted Answer
More Answers (2)
Matt Fig
on 6 May 2011
0 votes
You could set a timer callback to do this. Start by creating a list of the images in the file. This list will be updated and stored each time the timer callback fires. When the callback starts, make a call to DIR to get a list of *png files, then compare it to the stored list. If any name is in the directory but not in the stored list, send the name to IMREAD.
You don't show what you are doing with the image once it is read, this might affect what to do next....
Eric Keller
on 6 May 2011
0 votes
unless matlab has changed recently, it doesn't actually try to see if the file exists before it tells you it doesn't exist. It uses some cached directory listing. There is a command called "rehash" that will make it check. Looking at the help for rehash, it doesn't look like anything has changed.
If you really have problems with reading a file before the other program has finished writing it, you could write it to a different name and then change the name as the last thing. Much less likely to have a conflict. I have had to do this with gnuplot, but never with matlab.
Categories
Find more on Image Acquisition Support Packages for Hardware Adaptors (Generic Video Interface) 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!