How can we read an image along with its .pts file one by one?

2 次查看(过去 30 天)
I have face images along with their .pts file. I want to read face image one by one along with its .pts file.
I tried it. I am not getting any error in this code.
I just want to do this task using one for loop. So, I can read one face image along with its own .pts file (not all .pts files ) because if i will use two for loops in that case outside for loop will read first one image after that second for loop will read all .pts files,but i donot want this thing.
if true
% code
srcFiles = dir('E:\imagetest\*.jpg'); % the folder in which ur images exists
for j = 1 : length(srcFiles)
filename = strcat('E:\imagetest\',srcFiles(j).name);
I = imread(filename);
Filelist=dir('E:\TEST')% the folder in which .pts file exist
counter = 1;
FSize = size(Filelist);
for i=3:4%numel(Filelist)
filename = strcat('E:\TEST\',Filelist(i).name);
[FileId errmsg]=fopen(filename)
npoints=textscan(FileId,'%s %f',1,'HeaderLines',1);
points=textscan(FileId,'%f %f',npoints{2},'MultipleDelimsAsOne',2,'Headerlines',2)
Y=cell2mat(points);
end
end
end
%%Example of .pts file
version: 1
n_points: 4
{
115.947 221.239
121.382 250.566
130.001 279.096
141.677 306.538
}

采纳的回答

Walter Roberson
Walter Roberson 2015-5-19
imgdir = 'E:\imagetest';
ptsdir = 'E:\TEST';
jpegwild = fullfile(imgdir, '*.jpg');
srcFiles = dir(jpegwild); % the folder in which ur images exists
for j = 1 : length(srcFiles)
imgfilename = srcFiles(j).name;
fullimgfilename = fullfile(imgdir,imgfilename);
[filepath, basename, ext] = fileparts(imgfilename);
fullptsfilename = fullfile(testdir, [basename '.pts']);
if ~exist(fullptsfilename,'file')
fprintf(2, 'Image "%s" did not have a corresponding .pts file\n", imgfilename);
continue;
end
I{j} = imread(fullimgfilename);
[FileId, errmsg] = fopen(fullptsfilename);
npoints = textscan(FileId,'%s %f',1,'HeaderLines',1);
points = textscan(FileId,'%f %f', npoints{2}, 'MultipleDelimsAsOne', 2, 'Headerlines', 2, 'CollectOutput, 1);
fclose(FileId);
Y{j} = points{1};
end
This forms the cell arrays I{k} being the k'th image and Y{k} being the corresponding points
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Geometric Transformation and Image Registration 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by