locateText

Class: ocrText

Locate text pattern

Syntax

bboxes = locateText(ocrText,pattern)
bboxes = locateText(ocrText,pattern,Name, Value)

Description

bboxes = locateText(ocrText,pattern) returns the location and size of bounding boxes stored in the ocrText object. The locateText method returns only the locations of bounding boxes which correspond to text within an image that exactly match the input pattern.

bboxes = locateText(ocrText,pattern,Name, Value) uses additional options specified by one or more Name,Value arguments.

Input Arguments

expand all

Recognized text and metrics, returned as an ocrText object. The object contains the recognized text, the location of the recognized text within the input image, and the metrics indicating the confidence of the results. The confidence values range between 0 and 100 and represent a percent probability. When you specify an M-by-4 roi, the function returns ocrText as an M-by-1 array of ocrText objects. Confidence values range between 0 and 1. Interpret the confidence values as probabilities.

OCR character vector pattern, specified as a single character vector, string scalar, cell array of character vectors, or a string array. The method returns onlythe locations of bounding boxes which correspond to text within an image that exactly match the input pattern.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Regular expression, specified as a logical scalar. When you set this property to true, the method treats the pattern as a regular expression. For more information about regular expressions, see regexp.

Case sensitivity, specified as a logical scalar. When you set this property to true, the method performs case-insensitive text location.

Output Arguments

expand all

Text bounding boxes, specified 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. The ocr function stores OCR results in the ocrText object.

Examples

expand all

businessCard = imread('businessCard.png');
ocrResults = ocr(businessCard);
bboxes = locateText(ocrResults, 'MathWorks', 'IgnoreCase', true);
Iocr = insertShape(businessCard, 'FilledRectangle', bboxes);
figure; imshow(Iocr);

     businessCard = imread('businessCard.png');
     ocrResults   = ocr(businessCard);
     bboxes = locateText(ocrResults, 'www.*com','UseRegexp', true);
     img    = insertShape(businessCard, 'FilledRectangle', bboxes);
     figure; imshow(img);