myFolder = 'folder';
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
filePattern = fullfile(myFolder, '*.jpg');
matFiles = dir(filePattern);
for k = 1:length(matFiles)
baseFileName = matFiles(k).name;
img = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', img);
storedStructure = imread(img);
FaceDetect = vision.CascadeObjectDetector;
FaceDetect.MergeThreshold = 7 ;
BB = step(FaceDetect,storedStructure);
for i = 1:size(BB,1)
rectangle('Position',BB(i,:),'LineWidth',3,'LineStyle','- ','EdgeColor','r');
end
for i = 1:size(BB,1)
J= imcrop(storedStructure,BB(i,:));
figure
imshow(J);
[~, baseFileNameNoExt, ~] = fileparts(baseFileName);
outputFolder = fullfile(myFolder, baseFileNameNoExt);
if ~exist(outputFolder, 'dir')
mkdir(outputFolder);
fprintf('Created folder : %s\n', outputFolder);
end
outputFileName = fullfile(outputFolder, baseFileName);
imwrite(J, outputFileName);
fprintf(' Copied %s to the folder called %s.\n', baseFileName, outputFolder);
end
end
J
HOG(J)
X=HOG(J)
save('features.mat','J');