UNABLE TO PERFORM ASSIGMENT BECAUSE THE SIZE OF THE LEFT SIDE IS 1 BY 1260 AND THE SIZE OF THE RIGHT SIDE IS 1 BY 5040
1 次查看(过去 30 天)
显示 更早的评论
function matr_text=ocr(im, bb)
Dir="C:\Users\Usuario\Downloads\vcc2\vcc";
trainingSet = imageDatastore(Dir,'IncludeSubfolders',true,'LabelSource','foldernames');
countEachLabel(trainingSet)
numImages = numel(trainingSet.Files);
img = readimage(trainingSet, 1);
[hog_4x4, vis4x4] = extractHOGFeatures(img,'CellSize',[4 4]);
plot(vis4x4)
cellSize = [4 4];
hogFeatureSize = length(hog_4x4);
trainingFeatures = zeros(numImages,hogFeatureSize,'single');
for i = 1:numImages
img = readimage(trainingSet,i);
img = rgb2gray(img);
% Apply pre-processing steps
img = imbinarize(img);
trainingFeatures(i,:) = extractHOGFeatures(img, 'CellSize',cellSize);
end
% Get labels for each image.
trainingLabels = trainingSet.Labels;
classifier = fitcecoc(trainingFeatures, trainingLabels);
[m, n] = size(bb)
for j = 1:m
img = imcrop(im, bb(j,:));
figure, imshow(img)
img = rgb2gray(img);
% Apply pre-processing steps
img = imbinarize(img);
img=imresize(img, [45,60])
figure, imshow(img)
features(j,:) = extractHOGFeatures(img,'CellSize',cellSize);
end
% Make class predictions using the test features.
predictedLabels = predict(classifier, features);
end
2 个评论
Torsten
2023-1-6
Anything unclear about the error message ?
hogFeatureSize is 1260, but you need it to be 5040, thus 4*1260.
Image Analyst
2023-1-27
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!