Image.ocr#

Image.ocr(minconf: int = 50, plot: bool = False, return_bbox: bool = False) → list[OCRWord][source]#

Optical character recognition

Parameters:
  • minconf (int, optional) – minimum confidence value for text to be returned or plotted (percentage), defaults to 50

  • plot (bool, optional) – overlay detected text on the current plot, assumed to be the image, defaults to False

Returns:

detected strings and metadata

Return type:

list of OCRWord

Examples

>>> from machinevisiontoolbox import Image
>>> img = Image.Read('penguins.png')
>>> for word in img.ocr(minconf=90):
...     print(word)
pytesseract is required for OCR functionality. Install it with: pip install pytesseract or pip install machinevision-toolbox-python[ocr]
Install the tesseract OCR engine from https://github.com/tesseract-ocr/tesseract?tab=readme-ov-file#installing-tesseract

Each recognized text string is described by an OCRWord instance that contains the string, confidence and bounding box within the image.

Warning

PyTessearct must be installed.

References

See also

OCRWord