error in reading frames

조회 수: 21 (최근 30일)
Pat
Pat 2012년 3월 14일
i have 140 frames in E drive
path ='E:\surframes\';
files = dir(fullfile(path,'*.jpg'));
I = ((imread(fullfile(path,files(82:118).name))));
i want to read frames 82 to 118,but i get error as
Error using ==> imread at 372
File
"E:\surframes\23.jpg\24.jpg\25.jpg\26.jpg\27.jpg\28.jpg\29.jpg\3.jpg\30.jpg\31.jpg\32.jpg\33.jpg\34.jpg\35.jpg\36.jpg\37.jpg\38.jpg\39.jpg\4.jpg\40.jpg\41.jpg\42.jpg\43.jpg\44.jpg\45.jpg\46.jpg\47.jpg\48.jpg\49.jpg\5.jpg\50.jpg\51.jpg\52.jpg\53.jpg\54.jpg\55.jpg\56.jpg"
does not exist.
Error in ==> final at 26
I = ((imread(fullfile(path,files(82:118).name))));
my frames are ordered from 1 to 140
please help

채택된 답변

Geoff
Geoff 2012년 3월 14일
You're constructing one filename out of lots of them. You're also assuming that the files are listed in order. You need to get the frame number from the file name.
Try this:
I = {};
for f = 1:length(files)
file = files(f).name;
frame = num2str( file(1:find(file,f=='.',1)-1) );
if frame >= 82 && frame <= 118
I{frame} = imread(fullfile(path,file));
end
end
Now you have a cell-array where the elements I{82} through to I{118} will contain your loaded images.
  댓글 수: 1
Geoff
Geoff 2012년 3월 14일
Note, edited original post. Had not noticed your assumption about the files list indices being the same as the actual frame numbers.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by