Drawing results
The input ImageTensor (or ImageTensorU8) can render inference results directly onto the image: bounding boxes, segmentations, barcodes, and optional labels. The in-memory output is uint8 RGB in [batch, height, width, 3] (BHWC) layout.
Overlay behavior
- Labels are multi-line chips placed above each box when possible (below the box if there is no room above), so the object stays visible.
- Standalone classification scores are sorted from highest to lowest and drawn as separate class-colored chips in the top-left corner.
- OCR text is drawn as neutral chips in the top-left corner. Text associated with geometry is also included on that geometry's label.
- Nested OD → classification: the label leads with the top classification score(s); the detector class line is omitted when classifications are present. OCR text children are shown as
"…". - Color: for OD → classification, both the box outline and the label use the top nested classification class color (not the detector class, and not split colors). Otherwise the geometry's own class color is used.
- Box outline is expanded slightly outward and supports a configurable line width so thick strokes do not cover the object.
- Python
- C#
- C / C++
import denkflow
pipeline = denkflow.Pipeline.from_denkflow("path/to/model.denkflow", pat="YOUR-PAT")
simplified = denkflow.SimplifiedPipeline(pipeline)
image_tensor = denkflow.ImageTensor.from_file("path/to/image.jpg")
results = simplified.run(image_tensor, confidence_threshold=0.5)
annotated = image_tensor.to_images_with_annotations(
results,
annotation_label_font_size=16.0,
top_classifications=1,
bounding_box_line_width=2,
save_path="annotated.png", # optional; batch > 1 is saved as a grid
)
Parameters:
segmentation_fill_alpha:Noneor0for outline-only segmentations; a value in(0, 1]fills at that opacity. Higher values are more opaque.annotation_label_font_size:Noneto skip labels; otherwise a size relative to a 1080px-tall reference image. This also enables classification and OCR chips in the top-left corner.top_classifications: how many classification scores (highest first) to draw (0omits them; default1). Standalone scores are stacked in the top-left corner; nested scores appear on their geometry label.bounding_box_line_width: outline thickness in pixels (default1).draw_orientation_lines: draws orientation lines on rotated boxes.save_path: optional path to write the annotated image(s). Format is taken from the extension. With a batch larger than one, images are arranged into a near-square grid and saved as a single file.
ImageTensorU8 exposes the same to_images_with_annotations(...) method.
using DenkFlow;
using var license = HubLicenseSource.FromPat("YOUR-PAT");
using var pipeline = Pipeline.FromDenkflow("path/to/model.denkflow", license);
using var simplified = new SimplifiedPipeline(pipeline);
using var imageTensor = ImageTensor.FromFile("path/to/image.jpg");
var options = new AnnotationOptions(
DrawOrientationLines: true,
SegmentationFillAlpha: 0,
LabelFontSize: 16,
TopClassifications: 1,
BoundingBoxLineWidth: 2,
SavePath: "annotated.png");
using ImageInferenceResults results =
simplified.Run(imageTensor, confidenceThreshold: 0.5f);
ImageData annotated =
imageTensor.ToImagesWithAnnotations(results, options);
Console.WriteLine(
$"{annotated.Width}x{annotated.Height}, {annotated.Channels} channels");
Like Python, C# runs inference first and then asks the source tensor to draw
those results. ImageInferenceResults retains the native representation needed
for drawing, so keep it alive through ToImagesWithAnnotations and dispose it
afterward. The input tensor is cloned for inference and remains caller-owned.
AnnotationOptions uses the same controls described in the Python tab.
Use 0 for outline-only segmentations or no labels. Increasing
SegmentationFillAlpha makes the fill more opaque. Set SavePath to null
to keep the result in memory only. Standalone classification scores are
stacked in the top-left corner and limited by TopClassifications; OCR text is
stacked there as well.
File-path and raw-buffer Run overloads also return ImageInferenceResults,
but annotation still requires a caller-held ImageTensor or ImageTensorU8
containing the corresponding source images.
// run_from_tensor / run_from_file consume the tensor; load a second tensor for annotation.
DenkflowImageTensor* annotation_tensor = NULL;
denkflow_image_tensor_from_file(&annotation_tensor, image_path);
/* The result is a DenkflowImage: RGB pixels in BHWC layout. */
DenkflowImage* annotated = NULL;
denkflow_image_tensor_to_images_with_inference_results(
annotation_tensor,
inference_results,
false, /* draw_orientation_lines */
0.0f, /* segmentation_fill_alpha: 0 = outline segmentations */
16.0f, /* annotation_label_font_size: 0 = no labels */
1, /* top_classifications */
2, /* bounding_box_line_width (0 is treated as 1) */
"annotated.png",/* save_path: NULL to skip writing a file */
&annotated);
/* Access the pixels via annotated->buffer, annotated->batch,
annotated->height, annotated->width, annotated->channels. */
denkflow_image_free(&annotated);
denkflow_image_tensor_free(&annotation_tensor);
Parameters (same semantics as Python):
segmentation_fill_alpha:0.0disables fill (outline only);(0, 1]fills at that opacity, with higher values more opaque.annotation_label_font_size:0.0skips labels; otherwise relative to a 1080px-tall reference image and enables classification and OCR chips in the top-left corner.top_classifications: number of classification scores to draw (0omits them). Standalone scores are stacked in the top-left corner; nested scores appear on their geometry label.bounding_box_line_width: outline thickness in pixels (0→1).save_path: optional filesystem path (NULLto skip). Batch size > 1 is saved as one near-square grid. Format comes from the file extension.
For ImageTensorU8 inputs, use denkflow_image_tensor_u8_to_images_with_inference_results with the same argument list.
run_from_file and run_from_tensor consume the image, so a separate tensor is loaded for annotation. The returned DenkflowImage holds the RGB pixels in [batch, height, width, channels] (BHWC) order and is released with denkflow_image_free.