My score is always zero, please help. I am new to matlab. My code is below
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
trainingDirectory = fullfile(*);
testingDirectory = fullfile(*);
% |imageDatastore| recursively scans the directory tree containing the
% images. Folder names are automatically used as labels for each image.
trainingSet = imageDatastore(trainingDirectory, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
testingSet = imageDatastore(testingDirectory, 'IncludeSubfolders', true, 'LabelSource', 'foldernames');
%% Extract HOG features from the train set.
numOfTrainImages = numel(trainingSet.Files);
cellSize=[8 8];
trainingFeatures = [];
trainingLabels = [];
for i = 1:numOfTrainImages
img = readimage(trainingSet, i);
img = imbinarize(img);
img = ~bwmorph(img,'thin',Inf);
%[extractFeatures,visuals]= extractHOGFeatures(img);
trainingFeatures(i,:)= extractHOGFeatures(img,'CellSize',cellSize);
end
% Get labels for each image.
trainingLabels = trainingSet.Labels;
classifier = fitcsvm(trainingFeatures, trainingLabels);
%% Extract HOG features from the test set.
setLabels = testingSet.Labels;
numOfTestImages = numel(testingSet.Files);
testingFeatures = [];
for i = 1:numOfTestImages
img = readimage(testingSet, i);
img = imbinarize(img);
img = ~bwmorph(img,'thin',Inf);
%[extractFeatures,visuals]= extractHOGFeatures(img);
testingFeatures(i,:)= extractHOGFeatures(img,'CellSize',cellSize);
end
[label,bothscores] = predict(classifier,trainingFeatures);
score = bothscores(:,1);
msgbox(sprintf('%.6f',score));
2 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Feature Detection and Extraction 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!