Skip to main content
Version: 0.10.x [Latest Beta]

Optical character recognition (OCR)

An OCR pipeline detects text regions and recognizes their content. Each detected region is a top-level InferenceResult with a bounding_box, and the recognized text is carried on its sub_results. See SimplifiedPipeline for the shared setup.

import denkflow

pipeline = denkflow.Pipeline.from_denkflow("path/to/model.denkflow", pat="YOUR-PAT")
simplified = denkflow.SimplifiedPipeline(pipeline)

results = simplified.run("path/to/image.jpg", confidence_threshold=0.5)

for image_result in results:
for r in image_result.results:
for sub in r.sub_results:
if sub.text is not None:
print(sub.text)

Draw OCR text​

Enable annotation labels to draw recognized OCR text as neutral chips in the top-left corner. Text associated with a detected region is also included on that region's label. Set annotation_label_font_size in Python or LabelFontSize in C# to a positive value; use the corresponding C annotation function's annotation_label_font_size argument. See Drawing results.