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 view (last 30 days)
Show older comments
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 Comments
Torsten
on 6 Jan 2023
Anything unclear about the error message ?
hogFeatureSize is 1260, but you need it to be 5040, thus 4*1260.
Image Analyst
on 27 Jan 2023
If you have any more questions, then attach your data and code to read it in with the paperclip icon after you read this:
Answers (0)
See Also
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!