Skip to content

中文 | English

API: wingman.ocr ​

OCR module providing text recognition based on the Tesseract engine.

Note

This module requires Tesseract to be installed. When it is not installed, a stub implementation is returned.

Module Overview ​

The ocr module provides text recognition:

  • Text recognition - recognize text in a specified region
  • Simplified recognition - return the recognized text directly

Recognize Text ​

recognize(region) / recognize(region) ​

Description: Recognizes text in the specified region and returns a detailed result.

Function signature:

python
recognize(region: dict) -> dict
lua
recognize(region: table) -> table

Parameters:

  • region - required, the recognition region {x: number, y: number, width: number, height: number}

Returns:

  • Recognition result object:
    • success / success - whether the call succeeded
    • text / text - the recognized text
    • confidence / confidence - confidence (0-100 integer percentage)
python
from wingman import ocr

# 识别指定区域
result = ocr.recognize({"x": 100, "y": 100, "width": 200, "height": 50})
if result['success']:
    print(f"识别成功: {result['text']}")
    print(f"置信度: {result['confidence']}")

Simplified Recognition ​

recognize_text(region) / recognizeText(region) ​

Description: Simplified text recognition that returns the text directly.

Function signature:

python
recognize_text(region: dict) -> str | None
lua
recognizeText(region: table) -> string | nil

Parameters:

  • region - required, the recognition region {x: number, y: number, width: number, height: number}

Returns:

  • The recognized text, or None/nil on failure
python
from wingman import ocr

text = ocr.recognize_text({"x": 0, "y": 0, "width": 300, "height": 100})
if text:
    print(f"识别到: {text}")

Available Interfaces ​

Python functionLua functionDescriptionParameters
recognize(region)recognize(region)Recognize textregion: recognition region (required)
Return: result object
recognize_text(region)recognizeText(region)Simplified recognitionregion: recognition region (required)
Return: text or None/nil

Language Pack Configuration ​

Tesseract language packs must be downloaded separately.

Download Language Packs ​

Download the required .traineddata files from tessdata:

LanguageFile name
Englisheng.traineddata
Simplified Chinesechi_sim.traineddata
Traditional Chinesechi_tra.traineddata
Japanesejpn.traineddata
Koreankor.traineddata

Install Language Packs ​

Place the downloaded .traineddata files into Tesseract's tessdata directory:

Windows (vcpkg installation):

<vcpkg-root>\installed\x64-windows\share\tesseract\tessdata\

Build Options ​

The OCR feature requires Tesseract to be installed:

bash
vcpkg install tesseract

If you do not need the OCR feature, you can disable it at build time:

bash
cmake -DWINGMAN_ENABLE_OCR=OFF ..

When disabled, a stub implementation is used and recognize() always returns an empty result.