Ctrl+K
Logo image Logo image

Site Navigation

  • API Reference
  • Examples

Site Navigation

  • API Reference
  • Examples

Section Navigation

  • PyFlink Table
  • PyFlink DataFrame
  • PyFlink Multimodal
    • Image
    • Video
    • Utilities
  • PyFlink DataStream
  • PyFlink Common

pyflink.multimodal.operators.image_ocr#

image_ocr(*columns, lang=None, model_sharing=None, concurrency=None, batch_size=None, num_gpus=None, gpu_type=None)[source]#

Create an OCR text extraction UDF (EasyOCR-based).

Requires pip install easyocr. This is a pandas batch UDF. EasyOCR accepts only a CPU/GPU boolean switch here: num_gpus > 0 requests a Flink GPU resource and enables EasyOCR GPU mode, while gpu_type is used to validate the assigned Flink GPU label before loading. EasyOCR does not expose explicit CUDA device placement through this operator. Inference currently runs per image so mixed-size batches do not need padding; batch_size mainly controls Python/Arrow batching overhead.

Parameters
  • *columns – Optional image column(s). When provided, the UDF is applied directly instead of returning a factory.

  • lang – List of language codes, e.g. ["en"], ["en", "ch_sim"]. None (default) uses ["en"].

  • model_sharing – Model sharing mode across parallel subtasks. None uses per-process caching.

  • concurrency – UDF concurrency. None uses the framework default.

  • batch_size – Pandas batch size. None uses the framework default.

  • num_gpus – Fractional GPU count per subtask, e.g. 0.5. Values greater than 0 enable EasyOCR GPU mode; None and 0 run on CPU.

  • gpu_type – Required Flink GPU resource label, e.g. "A10". None accepts any assigned GPU label. EasyOCR itself receives only the boolean GPU switch.

Returns

A UDF that returns a list of dicts with text, confidence, bbox keys. bbox is a four-point polygon [[x1, y1], ...] in image coordinates, preserving rotated text regions returned by EasyOCR.

Example:

>>> # As a reusable variable
>>> ocr = image_ocr(lang=["en", "ch_sim"])
>>> df = df.with_column("text", ocr(col("img")))
>>>
>>> # Inline
>>> df = df.with_column("text", image_ocr(col("img")))

previous

pyflink.multimodal.operators.image_segment

next

pyflink.multimodal.operators.image_detect_subplot

Show Source

Created using Sphinx 4.5.0.