OCR Processing
This example shows how to load a pre-built OCR pipeline from a .denkflow
file.
- Python
from denkflow import Pipeline, ImageTensor
# --- Configuration ---
pat = "YOUR-PAT-TOKEN"
denkflow_path = "path/to/your_exported_ocr.denkflow"
# For other ways to configure licensing (e.g., OneTimeLicenseSource, specific license IDs),
# refer to the "Configuration Options" section.
# --- Pipeline Creation ---
# The simplest way to load a .denkflow pipeline using a PAT:
pipeline = Pipeline.from_denkflow(denkflow_path, pat=pat)
# --- Inspection ---
print("Pipeline Structure:")
print(pipeline)
# --- Initialization ---
pipeline.initialize()
# --- Subscribe to Outputs (Adjust topic names based on print(pipeline)) ---
# Example topic names
bbox_topic = "bounding_box_filter_node/filtered_bounding_boxes" # Boxes for text regions. Coordinates are normalize in [0.0, 1.0].
ocr_topic = "ocr_node/output" # OCR text output
detection_receiver = pipeline.subscribe_bounding_box_tensor(bbox_topic)
text_receiver = pipeline.subscribe_ocr_tensor(ocr_topic)
# --- Publish Input Image (Adjust topic name based on print(pipeline)) ---
# Example topic name
input_image_topic = "camera/image"
image_path = "path/to/your/image.jpg" # Define image_path closer to its use
image = ImageTensor.from_file(image_path)
pipeline.publish_image_tensor(input_image_topic, image)
# --- Run Pipeline ---
pipeline.run()
# --- Receive and Process Results ---
detections = detection_receiver.receive().to_objects(0.5)
ocr_results = text_receiver.receive().to_objects() # List of strings
print(f"\nDetected {len(ocr_results)} text regions:")
for bbox, text in zip(detections, ocr_results):
print(f"- Text: '{text}'")
print(f" At BBox: ({bbox.x1}, {bbox.y1}), ({bbox.x2}, {bbox.y2})")