ocrText
Object for storing OCR results
Description
ocrText
object contains recognized text and metadata collected
during optical character recognition (OCR). You can access the information contained in the
object with the ocrText
properties. You can also locate text
that matches a specific pattern with the locateText
function.
Creation
Create an ocrText
object using the ocr
function.
Properties
Text
— Text recognized by OCR
array of characters
Text recognized by OCR, specified as an array of characters. The text includes white space and new line characters.
CharacterBoundingBoxes
— Bounding box locations
M-by-4 matrix
Bounding box locations, stored as an M-by-4 matrix. Each row of
the matrix contains a four-element vector, [x
y
width
height]. The [x
y] elements correspond to the upper-left corner of the bounding box.
The [width
height] elements correspond to the size of the rectangular region in
pixels. The bounding boxes enclose text found in an image using the ocr
function. Bounding boxes width and height that correspond to new line
characters are set to zero. Character modifiers found in languages, such as Hindi,
Tamil, and Bangalese, are also contained in a zero width and height bounding box.
CharacterConfidences
— Character recognition confidence
array
Character recognition confidence, specified as an array. The confidence values are
in the range [0, 1]. A confidence value, set by the ocr
function, should be interpreted as a probability. The ocr
function sets confidence values for spaces between words and sets new
line characters to NaN
. Spaces and new line characters are not
explicitly recognized during OCR. You can use the confidence values to identify the
location of misclassified text within the image by eliminating characters with low
confidence.
Words
— Recognized words
cell array
Recognized words, specified as a cell array.
WordBoundingBoxes
— Bounding box location and size
M-by-4 matrix
Bounding box location and size, stored as an M-by-4 matrix. Each row of the matrix contains a four-element vector, [x y width height], that specifies the upper left corner and size of a rectangular region in pixels.
WordConfidences
— Recognition confidence
array
Recognition confidence, specified as an array. The confidence values are in the
range [0, 1]. A confidence value, set by the ocr
function, should be interpreted as a probability. The ocr
function sets confidence values for spaces between words and sets new
line characters to NaN
. Spaces and new line characters are not
explicitly recognized during OCR. You can use the confidence values to identify the
location of misclassified text within the image by eliminating words with low
confidence.
Object Functions
locateText | Locate text pattern |
Examples
Find and Highlight Text in an Image
businessCard = imread("businessCard.png"); ocrResults = ocr(businessCard); bboxes = locateText(ocrResults,"MathWorks",IgnoreCase=true); Iocr = insertShape(businessCard,"FilledRectangle",bboxes); figure; imshow(Iocr);
Find Text Using Regular Expressions
businessCard = imread('businessCard.png'); ocrResults = ocr(businessCard); bboxes = locateText(ocrResults, 'www.*com','UseRegexp', true); img = insertShape(businessCard, 'FilledRectangle', bboxes); figure; imshow(img);
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Use in a MATLAB Function block is not supported.
The
Words
property cannot be accessed in code generation. Use theText
property in place of theWords
property to access the OCR results.
Version History
Introduced in R2014a
See Also
OCR
Trainer | ocr
| insertShape
| regexp
| strfind
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)