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

조회 수: 3 (최근 30일)
sweety
sweety 2015년 5월 19일
댓글: Walter Roberson 2016년 7월 31일
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
Aj_ti
Aj_ti 2016년 7월 31일
Then, how do I display the image?
Walter Roberson
Walter Roberson 2016년 7월 31일
imshow(I{j})
hold on
scatter(Y{j}(:,1), Y{j}(:,2), 'r*');
hold off

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

추가 답변 (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