How to run program once for every new image stored in folder?

2 ビュー (過去 30 日間)
Tan Jun Hao
Tan Jun Hao 2015 年 7 月 27 日
コメント済み: Tan Jun Hao 2015 年 7 月 27 日
I have a program to process all the JPEG photos in a folder. But what I want to do is to run the program once every time a new image is stored in the folder. Any ideas to do so?
My current code is something like that:
srcFiles = dir('C:\FTP\testing2\*.jpg');
for i = 1 : length(srcFiles)
filename = strcat('C:\FTP\testing2\', srcFiles(i).name);
I = imread(filename);
...........rest of my code..........
end
  3 件のコメント
Image Analyst
Image Analyst 2015 年 7 月 27 日
How are you defining what's "new"? New since last time you ran the program? If so, then are you saving, somewhere, the date and time of the last time you checked the folder or ran your script?
Tan Jun Hao
Tan Jun Hao 2015 年 7 月 27 日
I have a IP camera that snaps picture upon detecting motion. The photo is stored inside the folder directory. New photo meaning every time a new photo is saved inside the folder directory.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2015 年 7 月 27 日

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 27 日
folder='C:\FTP\testing2'
type='*.jpg'
srcFiles = dir(fullfile(folder,type));
for ii= 1 : length(srcFiles)
filename = fullfile(folder, srcFiles(ii).name);
I = imread(filename);
%Your code
%Store the result in a cell array, for example
Y{k}=I
end
What is the problem with your code
  3 件のコメント
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 27 日
That depends on how many files are contained in your folder. Check the number of files by typing
folder='C:\FTP\testing2'
type='*.jpg'
srcFiles = dir(fullfile(folder,type))
size(srcFiles )
Azzi Abdelmalek
Azzi Abdelmalek 2015 年 7 月 27 日
folder='C:\FTP\testing2'
type='*.jpg'
for k=:100
srcFiles = dir(fullfile(folder,type));
if ~isempty(srcFiles)
dat=datenum({srcFiles.date})
[~,ii]=min(dat)
nam=srcFiles(ii).name
filename = fullfile(folder, nam);
I = imread(filename);
%Your code
wait(2)
movefile(filename,fullfile(new_folder,nam)
end

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by