My score is always zero, please help. I am new to matlab. My code is below
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Feature Detection and Extraction en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!