OCR Module#

This module provides Optical Character Recognition (OCR) capabilities for images. Users can choose to rely solely on the provided functionalities of this module or use their own.

class go2.modules.ocr.ocr_module.OCRModule[source]#

Bases: DogModule

Users should not access or construct this class directly. Rather, they should access it through the Go2Controller instance.

extract_text_from_image(image: ndarray, config: OCRConfig = OCRConfig(cli_command='--oem 1 --psm 11 -c tessedit_char_whitelist="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "', min_conf=70, temporal_voting_threshold=3)) tuple[list[str], ndarray][source]#

Run OCR on a single image and return the detected text along with an annotated copy.

Parameters:
  • image (np.ndarray) – Input BGR image to extract text from.

  • config (OCRConfig, optional) – OCR configuration controlling preprocessing, confidence threshold, and Tesseract CLI options.

Returns:

The list of confidently detected words and the annotated image with bounding boxes drawn around them.

Return type:

tuple[list[str], np.ndarray]

extract_text_from_images_temporal_voting(images: ndarray[ndarray], config: OCRConfig = OCRConfig(cli_command='--oem 1 --psm 11 -c tessedit_char_whitelist="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "', min_conf=70, temporal_voting_threshold=3)) tuple[list[str], ndarray[ndarray]][source]#

Run OCR across multiple images of the same scene and keep only words detected in at least config.temporal_voting_threshold of them, reducing false positives from single-frame noise.

Parameters:
  • images (np.ndarray[np.ndarray]) – Array of input BGR images to extract text from.

  • config (OCRConfig, optional) – OCR configuration controlling preprocessing, confidence threshold, temporal voting threshold, and Tesseract CLI options.

Returns:

The list of words that met the temporal voting threshold and the array of annotated images corresponding to each input image.

Return type:

tuple[list[str], np.ndarray[np.ndarray]]

Raises:

ValueError – If the number of provided images is less than config.temporal_voting_threshold.

class go2.modules.ocr.ocr_config.OCRConfig(cli_command: str = '--oem 1 --psm 11 -c tessedit_char_whitelist="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "', min_conf: int = 70, temporal_voting_threshold: int = 3)[source]#

Bases: object

Immutable configuration for OCR extraction.

cli_command: str = '--oem 1 --psm 11 -c tessedit_char_whitelist="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 "'#

Tesseract CLI configuration string, passed directly to pytesseract as the config argument (e.g. OCR engine mode and page segmentation mode flags).

The default value sets three things:
  • --oem 1: OCR Engine Mode 1, which uses the LSTM neural-network-based recognizer only.

  • --psm 11: Page Segmentation Mode 11 (“sparse text”), which tells Tesseract to find as much text as possible without assuming any particular layout or reading order.

  • -c tessedit_char_whitelist="...": Restricts recognition to uppercase and lowercase ASCII letters, digits 0-9, and the space character. Any other character (punctuation, symbols, non-ASCII text) will not be recognized/output, which reduces noise at the cost of not being able to read text containing those excluded characters.

min_conf: int = 70#

Minimum per-word confidence (0-100) required for a detected word to be included in extracted text output. Words below this threshold are treated as noise and discarded.

temporal_voting_threshold: int = 3#

Minimum number of occurrences (votes) required across a sequence of frames for a word to be retained.