Filter löschen
Filter löschen

My score is always zero, please help. I am new to matlab. My code is below

2 Ansichten (letzte 30 Tage)
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));

Antworten (0)

Kategorien

Mehr zu Convert Image Type finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by