Condition on the last last frame of a video

1 次查看(过去 30 天)
Hello experts,
I extracted the frames of a video and are visible in the current folder (left column in matlab). I have 168 frames.
Before doing any analysis on the image, I want to put a condition on the last frame in the folder. The following code descirbes what I do.
RGB=imread('168.jpg');
I_gray= rgb2gray(RGB) ;
I_binrzd= imbinarize(I_gray,'global');
stats=regionprops('table',I_binrzd,'area');
C1=max(stats.area);
if C1>200
fprintf('SOFT');
end
Now I want Matlab to automatically imports the last frame and check the condition instead of me, saying 168! something like RGB=imread('end.jpg') !
Suggestions?
Thank you

采纳的回答

Guillaume
Guillaume 2018-11-12
Well, you need to ask the filesystem for the list of files, extract the file numbers from that list then select the greatest one, so:
filelist = dir('*.jpg'); %get list of files
filenumber = arrayfun(@(file) sscanf(file.name, '%d', 1), filelist); %extract file number
[~, selectedindex] = max(filenumber); %select greatest number
RGB = imread(filelist(selectedindex).name);
%... rest of your code

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing and Computer Vision 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by