ocr does not work well unless the letters are more than 20 pixels high. How high are your pixels?
help ocr
OCR Recognize text using Optical Character Recognition.
txt = OCR(I) returns an ocrText object containing the recognized text,
location of recognized characters, confidence of recognized characters,
recognized words, location of recognized words and confidence of recognized
words as properties. Confidence values range between 0 and 1 and should
be interpreted as probabilities.
txt = OCR(I, roi) recognizes text in I within one or more rectangular
regions defined by an M-by-4 matrix, roi. Each row of roi is a
four-element vector, [x y width height], that specifies the upper-left
corner and size of a rectangular region of interest in pixels. Each
rectangle must be fully contained within I.
[...] = OCR(...,Name=Value) specifies additional name-value pair
arguments described below:
'Language' Specify the language to recognize as a string or a
cell array of strings. The language can be specified
using the name of a language such as 'english',
'seven-segment' and 'japanese'.
A list of supported languages is shown in the documentation.
Custom trained languages are also supported.
Default: 'english'
'TextLayout' Specify the layout of the text within I as a string to perform
text segmentation. Valid string values are:
'auto' - Use 'TextLayout' as 'block' if 'Language' is
'seven-segment', otherwise use 'page'.
'page' - Treats the text in the image as a page containing
blocks of text.
'block' - Treats the text in the image as a single block
of text.
'line' - Treats the text in the image as single line of text.
'word' - Treats the text in the image as a single word of text.
'character' - Treats the text in the image as a single character.
Default: 'auto'
'CharacterSet' Specify the character set as a string of characters.
The classification process is constrained to select
the best matches from this smaller set of characters.
By default, all characters in the Language are used.
Default: ''
Class Support
-------------
The input image I can be logical, uint8, int16, uint16, single, or
double, and it must be real and nonsparse.
Notes
-------
The 'seven-segment' language uses '0 1 2 3 4 5 6 7 8 9 . : -' as character set.
Example 1 - Recognize text within an image
------------------------------------------
businessCard = imread('businessCard.png');
ocrResults = OCR(businessCard)
recognizedText = ocrResults.Text;
figure
imshow(businessCard)
text(600, 150, recognizedText, ...
BackgroundColor = [1 1 1])
Example 2 - Recognize text in regions of interest (ROI)
--------------------------------------------------------
I = imread('7segmentDisplay.jpg');
% Define one or more rectangular regions of interest within I.
roi = [1149,88,1106,375];
% You may also use DRAWRECTANGLE to select a region using a mouse:
% figure; imshow(I); rect = drawrectangle; roi = round(rect.Position);
ocrResults = OCR(I, roi, Language = 'seven-segment');
% Insert recognized text into original image.
Iocr = insertObjectAnnotation(I,'rectangle', ...
ocrResults.WordBoundingBoxes,ocrResults.Words);
figure
imshow(Iocr)
Example 3 - Display word bounding boxes and recognition confidences
-------------------------------------------------------------------
businessCard = imread('businessCard.png');
ocrResults = OCR(businessCard)
Iocr = insertObjectAnnotation(businessCard, 'rectangle', ...
ocrResults.WordBoundingBoxes, ...
ocrResults.WordConfidences);
figure
imshow(Iocr)
Example 4 - Find and highlight text in the image
------------------------------------------------
businessCard = imread('businessCard.png');
ocrResults = OCR(businessCard);
bboxes = locateText(ocrResults, 'MathWorks', IgnoreCase = true);
Iocr = insertShape(businessCard, 'FilledRectangle', bboxes);
figure
imshow(Iocr)
See also ocrTrainer, ocrText, ocrText>locateText, insertShape, insertText
Documentation for ocr
doc ocr