Main Content

locateText

Locate text pattern

Description

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

example

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

Examples

collapse all

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

Figure contains an axes object. The axes object contains an object of type image.

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

Figure contains an axes object. The axes object contains an object of type image.

Input Arguments

collapse 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 only the locations of bounding boxes which correspond to text within an image that exactly match the input pattern.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'IgnoreCase',true specifies case-insensitive text locations

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

collapse all

Text bounding boxes, returned 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.

Version History

Introduced in R2014a