({{, (RefLink[TextRecognize, paclet:ref/TextRecognize])[image] 
recognizes text in image and returns it as a string.}, {, (RefLink[TextRecognize, paclet:ref/TextRecognize])[image,level]
returns a list of strings at the specified structural level.}, {, (RefLink[TextRecognize, paclet:ref/TextRecognize])[image,level,prop]
returns prop for text at the given level.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[TextRecognize, paclet:ref/TextRecognize]) works with arbitrary grayscale and multichannel images, operating on the intensity value of each pixel.

(RefLink[TextRecognize, paclet:ref/TextRecognize])[{(Subscript[image, 1]),(Subscript[image, 2]),…}] returns recognition for all (Subscript[image, i]).

By default, the recognized text is returned as a single string for the whole image. Recognized text can be split into levels.

Structural elements specified in level include:

(RefLink[TextRecognize, paclet:ref/TextRecognize])[image,level,prop] computes prop at the given level and returns the result as a list {(Subscript[val, 1]),(Subscript[val, 2]),…}.

Possible settings for prop include:

The following options can be specified:

(RefLink[TextRecognize, paclet:ref/TextRecognize]) accepts a (RefLink[Language, paclet:ref/Language]) option. By default, (RefLink[Language, paclet:ref/Language]):>(RefLink[$Language, paclet:ref/$Language]) is used. Using (RefLink[Language, paclet:ref/Language])->{(Subscript[lang, 1]),(Subscript[lang, 2]),…} can be used to perform multi-language recognition.

The following (RefLink[Language, paclet:ref/Language]) settings can be used:

({{"Afrikaans", "Albanian", "Azerbaijani", "Belarusian"}, {"Bosnian", "Bulgarian", "Catalan", "Cebuano"}, {"ChineseSimplified", "ChineseTraditional", "Croatian", "Czech"}, {"Danish", "Dutch", "English", "Esperanto"}, {"Estonian", "Finnish", "French", "Galician"}, {"Georgian", "German", "Greek", "Haitian"}, {"Hungarian", "Icelandic", "Indonesian", "Irish"}, {"Italian", "Japanese", "Kazakh", "Kirghiz"}, {"Korean", "Lao", "Latin", "Lithuanian"}, {"Macedonian", "Malay", "Norwegian", "Polish"}, {"Portuguese", "Romanian", "Russian", "Serbian"}, {"Slovak", "Slovenian", "Spanish", "Swahili"}, {"Swedish", "Tajik", "Turkish", "Ukrainian"}, {"Uzbek", "Vietnamese", "Welsh", }})

By default, the text found anywhere in the image is returned. Use (RefLink[Masking, paclet:ref/Masking]) to specify the region of interest. Possible settings include:

(RefLink[RecognitionPrior, paclet:ref/RecognitionPrior]) makes an assumption about the kind of text present in the whole image or in each masked area. Possible settings include:

(RefLink[TextRecognize, paclet:ref/TextRecognize]) uses machine learning, and its training set and methods may change in different versions of the Wolfram Language, yielding different results.

OpenersPrimaryExamplesSection(Spacer1)Examples  (41)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Recognize text in an image:

TextRecognize[]

Recognize lines of text and their corresponding bounding boxes:

i=;

res=TextRecognize[i,"Line","BoundingBox"]

Highlight the bounding box of each recognized line:

HighlightImage[i,{"Boundary",res}]

OpenersExampleSection1(Spacer1)Scope  (14)

OpenersExampleSubsection0(Spacer1)Basic Uses  (5)

Recognize dark text on a bright background:

TextRecognize[]

Bright text on a dark background:

TextRecognize[]

Color image:

TextRecognize[]

Recognize a two-column text:

i=;

Snippet[TextRecognize[i],5]

OCR of a list of images:

TextRecognize[{,,}]

OpenersExampleSubsection1(Spacer1)Levels  (5)

The default recognition is performed on the whole image:

TextRecognize[]

Recognize the text on the image per paragraph:

TextRecognize[,"Block"];

Column[%,Dividers->Center]

Recognize the text on the image per line:

TextRecognize[,"Line"];

Column[%,Dividers->Center]

Recognize the text on the image per word:

TextRecognize[,"Word"]

Recognize the text on the image per character:

TextRecognize[, "Character"]

OpenersExampleSubsection2(Spacer1)Properties  (4)

By default, the recognized text is returned as a string:

i=;

TextRecognize[i]

The bounding box containing the recognized text:

TextRecognize[i,"BoundingBox"]

The strength of the recognition:

TextRecognize[i,"Strength"]

The image containing the recognized text:

TextRecognize[i,"Image"]

The subimages containing each word:

Framed/@TextRecognize[i,"Word","Image"]

Get the recognized text and its strength for each word:

TextRecognize[,"Word",{"Text","Strength"}]

Get the images of the recognized text per line:

Framed/@TextRecognize[,"Line","Image"]

Construct a dataset from multiple properties of the recognized text per word:

TextRecognize[, "Word", {"Text","Strength","BoundingBox","Image"}]//Dataset

OpenersExampleSection2(Spacer1)Options  (8)

OpenersExampleSubsection3(Spacer1)Language  (4)

The default recognition language is (RefLink[$Language, paclet:ref/$Language]):

$Language

TextRecognize[]

Specify the language of the text to recognize:

TextRecognize[,Language-> "German"]

Use an entity to specify the language:

TextRecognize[,Language-> (Entity["German", Entity["Language","German"], "Entity[\"Language\", \"German\"]", "language"])]

Recognize text containing multiple languages:

TextRecognize[,Language->{"German","Russian","Spanish"}]

OpenersExampleSubsection4(Spacer1)Masking  (1)

By default, using (RefLink[Masking, paclet:ref/Masking])->(RefLink[All, paclet:ref/All]), text in the whole image is recognized:

i=;

TextRecognize[i]

Specify the region of interest:

TextRecognize[i,Masking->Rectangle[{60,200},{145,240}]]

Use an image to specify the mask:

TextRecognize[i,Masking->]

Use a mask specifying multiple regions of interest:

TextRecognize[i,Masking->]

Use separate masks for each region of interest:

TextRecognize[i,Masking->{,}]

OpenersExampleSubsection5(Spacer1)RecognitionPrior  (3)

Specify that the image contains a single character:

TextRecognize[,RecognitionPrior->"Character"]

Without the prior, multiple characters may be returned:

TextRecognize[]

Without the correct prior, the text may be unrecognized:

TextRecognize[]

Specify the prior:

TextRecognize[,RecognitionPrior->"Character"]

Specify that the image contains a single word:

TextRecognize[,RecognitionPrior->"Word"]

Without the prior, multiple words may be recognized:

TextRecognize[]

OpenersExampleSection3(Spacer1)Applications  (6)

Perform a frequency analysis on the recognized text:

TextRecognize[]

WordFrequencyData[TextWords[%]]

Visualize the result, highlighting the less frequent words:

WordCloud[%,ScalingFunctions->(1/#&)]

Use (RefLink[LanguageIdentify, paclet:ref/LanguageIdentify]) to identify the language of some recognized text:

img=;
TextRecognize[img]

lang=LanguageIdentify[%]

Use the identified language to improve the OCR result:

TextRecognize[img,Language->lang]

Format the recognized text to interactively show the definition of each word:

text=TextRecognize[];

Write a function to look up a word's definition in the dictionary:

findDefinition[s_String]:=
Module[{word,defs},
word = DictionaryLookup[s,IgnoreCase->True];
If[word==={}, Return[Missing["NotAvailable"]]];
defs=WordData[Pluralize[First[word],1],"Definitions"];
If[Head[defs]===WordData, Return[Missing["NotAvailable"]]];
Grid[Transpose[{defs[[All,1,2]],defs[[All,2]]}],Alignment->Left]
]

Apply the function to the words present in the extracted text:

def=Normal@DeleteMissing[AssociationMap[Tooltip[#,findDefinition[#]]&,TextWords[text]],1,2];

Recombine the text in a single cell:

TextCell[Row[List@@StringReplace[text,def]],FontSize->11]

Recognize characters in a geometrical diagram:

image=;

Specify the regions that contain text:

mask =;

TextRecognize[image,Masking->mask,RecognitionPrior->"Character"]

Extract some properties and highlight them on the image:

res=TextRecognize[image,"Character",{"Text","BoundingBox","Strength"},Masking->mask,RecognitionPrior->"Character"];

Highlight each character with the recognized text and strength:

HighlightImage[image,MapThread[Tooltip[#1, {#2, #3}]&, {res[[All,2]], res[[All, 1]], res[[All, 3]]}]]

Recognize lines of text and their corresponding bounding boxes:

i=;

res=TextRecognize[i,"Line",{"Text","BoundingBox"}]

Highlight the bounding box of each recognized line using a tooltip for each box:

HighlightImage[i,{"Boundary",MapThread[Tooltip[#1, #2]&, {res[[All,2]], res[[All, 1]]}]}]

Recognize, group and highlight all occurrences of a single word in an image:

image = ;

result=TextRecognize[image, "Word", {"Text", "BoundingBox"}]

res2=Normal[GroupBy[result,(#[[1]]&)->(#[[2]]&)]][[All,2]]

HighlightImage[image,Riffle[res2,RandomColor[Length[res2]-1]]]

OpenersExampleSection4(Spacer1)Properties & Relations  (2)

Recognize warped text:

TextRecognize[,Language->"Russian"]

By default, the whole image is assumed to be the region of interest:

TextRecognize[]

Remove all the new lines:

TextRecognize[]//StringReplace[#,"\n"->" "]&

Replace extra new lines with a single new line:

TextRecognize[]//StringReplace[#,"\n\n"->"\n"]&

OpenersExampleSection5(Spacer1)Possible Issues  (8)

Rotated text may not be recognized correctly:

i=ImageRotate[, 0.15,Background->White]

TextRecognize[i]

Text of different colors may not be recognized:

TextRecognize[]

The quality of recognized text may improve by processing the image:

Closing[LocalAdaptiveBinarize[, 1],1]

TextRecognize[%]

Fonts smaller than a certain size cannot be recognized:

TextRecognize[]

The quality of recognized text may improve by enlarging the image:

TextRecognize[ImageResize[, Scaled[3.5]]]

When recognizing formatted numbers, whitespace may cause OCR errors:

TextRecognize[]

Text of different colors may not be fully recognized:

img=;

TextRecognize[img]

Separately segment red and white text:

colormask=(ImageMultiply[#,#]&)/@ImageAdjust/@ColorNegate[ColorDistance[img,{Red,White}]]

Combine segmented text and sharpen the image:

Sharpen[ImageAdjust@ImageAdd[colormask]]

Recognize text:

TextRecognize[%]

Text given as outlines cannot be recognized properly:

img=;

TextRecognize[img]

Fill the background to improve the result:

DeleteSmallComponents@Binarize@RemoveAlphaChannel[RemoveBackground[img],Black]

TextRecognize[%]

Text surrounded by some non-textual content may not be properly recognized:

i=;

TextRecognize[i]

Trim the textual part of the image to improve the result:

ImageTrim[i,{{15,15},{210,85}}]

TextRecognize[%]

Sometimes small text in a large image is not recognized:

i=;

TextRecognize[i,"Line"]

Specify the regions that contain text to improve recognition:

TextRecognize[i,"Line",Masking->]

OpenersExampleSection6(Spacer1)Neat Examples  (1)

Read from a book cover:

TextRecognize[]//Speak

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[LanguageIdentify, paclet:ref/LanguageIdentify])  ▪  (RefLink[BarcodeRecognize, paclet:ref/BarcodeRecognize])  ▪  (RefLink[ImageIdentify, paclet:ref/ImageIdentify])  ▪  (RefLink[ImageCases, paclet:ref/ImageCases])  ▪  (RefLink[SpeechRecognize, paclet:ref/SpeechRecognize])  ▪  (RefLink[Classify, paclet:ref/Classify])  ▪  (RefLink[TextWords, paclet:ref/TextWords])  ▪  (RefLink[TextSentences, paclet:ref/TextSentences])  ▪  (RefLink[TextPosition, paclet:ref/TextPosition])  ▪  (RefLink[WordCloud, paclet:ref/WordCloud])  ▪  (RefLink[WordTranslation, paclet:ref/WordTranslation])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Feature Detection, paclet:guide/FeatureDetection])}, {▪(RefLinkPlain[Computer Vision, paclet:guide/ComputerVision])}, {▪(RefLinkPlain[Text Manipulation, paclet:guide/ProcessingTextualData])}, {▪(RefLinkPlain[Machine Learning, paclet:guide/MachineLearning])}, {▪(RefLinkPlain[Image Processing & Analysis, paclet:guide/ImageProcessing])}, {▪(RefLinkPlain[Computational Photography, paclet:guide/ComputationalPhotography])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/22-machine-learning.html])(WebLink[: Machine Learning, https://www.wolfram.com/language/elementary-introduction/22-machine-learning.html])}})}})