Digit recognition using MATLAB (Support Vector Machine + HOG)
clc;
clear all;
close all;
warning off;
imds=imageDatastore('database','IncludeSubFolders',true,'LabelSource','foldernames');
trainingFeatures=[];
trainingLabels=imds.Labels;
for i = 1:numel(imds.Files)
% Read images using a for loop
img = readimage(imds,i);
trainingFeatures(i,:) =
extractHOGFeatures(img,'CellSize',[8 8]);
end
Classifier =fitcecoc(trainingFeatures,trainingLabels);
save Classifier Classifier
%Testing Code:
clc;
clear all;
close all;
warning off;
load Classifier;
[filename, pathname] = uigetfile('*.*', 'Pick an
Image');
filename=strcat(pathname,filename);
imga=imread(filename);
img=imresize(imga,[45 24]);
[Features] = extractHOGFeatures(img,'CellSize',[8 8]);
PredictedClass=predict(Classifier,Features);
PredictedClass=char(PredictedClass);
figure;imshow(imga),title(PredictedClass);
disp(PredictedClass);
No comments