Skip to content

text_OCRTesseract

textclassOpenCV 5.0.0
import { text_OCRTesseract } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

Native object: release it with using or delete(). Factories can return null; check before calling methods. Inherits text_BaseOCR.

OCRTesseract class provides an interface with the tesseract-ocr API (v3.02.02) in C++.

Notice that it is compiled only when tesseract-ocr is correctly installed.

Note: - (C++) An example of OCRTesseract recognition combined with scene text detection can be found at the end_to_end_recognition demo: https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/end_to_end_recognition.cpp - (C++) Another example of OCRTesseract recognition combined with scene text detection can be found at the webcam_demo: https://github.com/opencv/opencv_contrib/blob/master/modules/text/samples/webcam_demo.cpp

Constructors and members

static create

Creates an instance of the OCRTesseract class. Initializes Tesseract.

Note: The char_whitelist default is changed after OpenCV 4.7.0/3.19.0 from "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" to "".

create(datapath: EmbindString, language: EmbindString, char_whitelist: EmbindString, oem: number, psmode: number): text_OCRTesseract | null;
6 available overloads
create(): text_OCRTesseract | null;
create(datapath: EmbindString): text_OCRTesseract | null;
create(datapath: EmbindString, language: EmbindString): text_OCRTesseract | null;
create(datapath: EmbindString, language: EmbindString, char_whitelist: EmbindString): text_OCRTesseract | null;
create(datapath: EmbindString, language: EmbindString, char_whitelist: EmbindString, oem: number): text_OCRTesseract | null;
create(datapath: EmbindString, language: EmbindString, char_whitelist: EmbindString, oem: number, psmode: number): text_OCRTesseract | null;
datapath

the name of the parent directory of tessdata ended with "/", or NULL to use the system's default directory.

language

an ISO 639-3 code or NULL will default to "eng".

char_whitelist

specifies the list of characters used for recognition. NULL defaults to "" (All characters will be used for recognition).

oem

tesseract-ocr offers different OCR Engine Modes (OEM), by default tesseract::OEM_DEFAULT is used. See the tesseract-ocr API documentation for other possible values.

psmode

tesseract-ocr offers different Page Segmentation Modes (PSM) tesseract::PSM_AUTO (fully automatic layout analysis) is used. See the tesseract-ocr API documentation for other possible values.

Returns

The text_OCRTesseract | null result.

clone

Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.

clone(): this;
Returns

The this result.

run

aliases for scripting

run(image: Mat, min_confidence: number, component_level: number): string;
2 available overloads
run(image: Mat, min_confidence: number): string;
run(image: Mat, min_confidence: number, component_level: number): string;
image

image argument (Mat).

min_confidence

min confidence argument (number).

component_level

component level argument (number).

Returns

The string result.

run1

aliases for scripting

run1(image: Mat, mask: Mat, min_confidence: number, component_level: number): string;
2 available overloads
run1(image: Mat, mask: Mat, min_confidence: number): string;
run1(image: Mat, mask: Mat, min_confidence: number, component_level: number): string;
image

image argument (Mat).

mask

mask argument (Mat).

min_confidence

min confidence argument (number).

component_level

component level argument (number).

Returns

The string result.

setWhiteList

Set the white list used by this text_OCRTesseract object.

setWhiteList(char_whitelist: EmbindString): void;
char_whitelist

char whitelist argument (EmbindString).

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.