How to save images in a folder?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to read 2 images, do something to those images and then save those two images in a folder. I have used for loop. I am able to read both the images but only first image is getting saved in the folder. Following is my code. What changes should be done in order to save both the images in a folder.
c=cell(1,2);
for m=1:2
I=imread(sprintf('isha%d.jpg',m));
%To detect Mouth
MouthDetect = vision.CascadeObjectDetector('Mouth','MergeThreshold',120);
BB=step(MouthDetect,I);
figure,
imshow(I); hold on
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',4,'LineStyle','-','EdgeColor','r');
end
x=imcrop(I,BB);
y= imcomplement(x);
figure, imshow(y);
imwrite(y,strcat('D:\implementation\featurescrop\mouth__',num2str(i),'.jpg'));
hold off;
%To detect Eyes
EyeDetect = vision.CascadeObjectDetector('EyePairBig');
BB=step(EyeDetect,I);
hold on
rectangle('Position',BB,'LineWidth',4,'LineStyle','-','EdgeColor','b')
x=imcrop(I,BB);
y= imcomplement(x);
figure, imshow(y);
imwrite(y,strcat('D:\implementation\featurescrop\eyes__',num2str(i),'.jpg'));
hold off;
%to detect nose
NoseDetect = vision.CascadeObjectDetector('Nose','MergeThreshold',85);
BB=step(NoseDetect,I);
figure,
imshow(I); hold on
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',4,'LineStyle','-','EdgeColor','b');
end
title('Nose Detection');
hold off;
x=imcrop(I,BB);
y= imcomplement(x);
figure, imshow(y);
imwrite(y,strcat('D:\implementation\featurescrop\nose__',num2str(i),'.jpg'));
hold off;
end
4 commentaires
Ganesh Hegade
le 14 Déc 2016
Modifié(e) : Ganesh Hegade
le 14 Déc 2016
size command always return 1x2 double data. for example if
BB = [168,253,79,48];
>> size(BB)
ans =
1 4
size(BB,1) gives only the first value of the output.
BB = [168,253,79,48];
>> size(BB,1)
ans =
1
So in your code loop is running for only first element.
Réponses (1)
KSSV
le 15 Déc 2016
As the size(BB,1) is 1, your loop runs only for once....As you said you are reading two images....change loop to:
for i = 1:2
%%%%
end
0 commentaires
Voir également
Catégories
En savoir plus sur Computer Vision with Simulink dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!