Bounding Rectangle¶
Class: BoundingRectBlockV1
Source: inference.core.workflows.core_steps.transformations.bounding_rect.v1.BoundingRectBlockV1
Calculate the minimum rotated bounding rectangle around polygon segmentation masks, converting complex polygon shapes into simplified rectangular bounding boxes with orientation information for zone creation, region simplification, and rectangular area approximation based on detected object shapes.
How This Block Works¶
This block processes instance segmentation predictions with polygon masks and calculates the minimum rotated bounding rectangle (smallest rectangle that can enclose the polygon) for each detection. The block:
- Receives instance segmentation predictions containing polygon masks (validates that masks are present)
- Processes each detection's polygon mask individually
- Extracts the largest contour from the polygon mask (handles multi-contour masks by selecting the largest)
- Calculates the minimum rotated bounding rectangle using OpenCV's minAreaRect:
- Finds the smallest rotated rectangle that can completely enclose the polygon
- Determines the rectangle's center point, dimensions (width, height), and rotation angle
- Computes the four corner points of the rotated rectangle
- Updates the detection's mask to be a rectangular mask matching the calculated bounding rectangle (converts the rotated rectangle polygon back to a mask format)
- Updates the detection's axis-aligned bounding box (xyxy) to the bounding box of the rotated rectangle (fits the rotated rectangle into an axis-aligned box)
- Stores additional rectangle metadata in the detection data:
- Rectangle corner coordinates (rotated rectangle points)
- Rectangle width and height (dimensions of the rotated rectangle)
- Rectangle angle (rotation angle in degrees)
- Merges all processed detections and returns them with updated masks, bounding boxes, and rectangle metadata
The block transforms complex polygon shapes into simplified rectangular representations, preserving orientation information through the rotation angle. This is particularly useful when you need to create zones or regions based on detected object shapes (e.g., sports fields, road segments, marked areas) and want to simplify them to rectangular approximations. The minimum rotated rectangle provides the most compact rectangular representation of the polygon, potentially at an angle to minimize area.
Common Use Cases¶
- Zone Creation from Object Shapes: Convert detected polygon shapes into rectangular zones for area monitoring or analysis (e.g., create zones from basketball court detections, generate road segment zones from road markings, create rectangular regions from zebra crossing detections), enabling zone-based workflows from complex shapes
- Region Simplification: Simplify complex polygon shapes to rectangular approximations for easier processing (e.g., simplify irregular segmentation masks to rectangles, convert complex shapes to rectangular regions, approximate polygon areas with rectangles), enabling simplified region processing
- Rotated Region Detection: Detect and extract rotated rectangular regions from polygon detections (e.g., find rotated parking spaces from segmentation, detect angled road markings as rectangles, extract rotated objects as rectangular zones), enabling rotation-aware region extraction
- Area Approximation: Approximate polygon areas with compact rectangular bounding boxes (e.g., approximate sports field areas with minimal rectangles, estimate region sizes using rotated bounding boxes, calculate compact rectangular areas from complex shapes), enabling area estimation with rectangular approximations
- Shape Normalization: Normalize polygon shapes to rectangular representations for standardized processing (e.g., normalize detected shapes to rectangles for consistent analysis, standardize polygon regions to rectangular format, convert variable shapes to uniform rectangular regions), enabling shape normalization workflows
- Multi-Object Zone Extraction: Extract rectangular zones from multiple detected polygon objects (e.g., create zones from multiple road segment detections, generate rectangular regions from multiple field detections, extract zones from various marked area detections), enabling multi-object zone creation workflows
Connecting to Other Blocks¶
This block receives instance segmentation predictions with polygon masks and produces detections with rectangular masks and bounding boxes:
- After instance segmentation blocks to convert polygon masks to rectangular bounding boxes for zone creation or simplified processing, enabling rectangular zone generation from complex shapes
- Before zone-based blocks (e.g., Polygon Zone, Dynamic Zone) to prepare rectangular regions for zone-based workflows (e.g., create zones from simplified rectangles, use rectangular approximations for zone monitoring, enable zone workflows with rectangular regions), enabling zone-based workflows with simplified shapes
- After filtering blocks (e.g., Detections Filter) to process only specific polygon detections before converting to rectangles (e.g., filter detections by class before rectangular conversion, select specific polygon types for rectangle extraction, prepare filtered detections for zone creation), enabling selective rectangle extraction
- Before crop blocks to extract rectangular regions from polygon detections (e.g., crop rotated rectangular regions from polygon shapes, extract rectangular areas from complex detections, prepare rectangular crop regions from polygons), enabling rectangular region extraction
- Before visualization blocks to display simplified rectangular representations of complex polygons (e.g., visualize rectangular approximations of polygons, display rotated bounding rectangles, show simplified rectangular zones), enabling rectangular visualization outputs
- Before analysis blocks that work better with rectangular regions than complex polygons (e.g., analyze rectangular zones instead of polygons, process simplified rectangular regions, work with normalized rectangular shapes), enabling simplified region analysis workflows
Type identifier¶
Use the following identifier in step "type" field: roboflow_core/bounding_rect@v1to add the block as
as step in your workflow.
Properties¶
| Name | Type | Description | Refs |
|---|---|---|---|
name |
str |
Enter a unique identifier for this step.. | ❌ |
The Refs column marks possibility to parametrise the property with dynamic values available
in workflow runtime. See Bindings for more info.
Available Connections¶
Compatible Blocks
Check what blocks you can connect to Bounding Rectangle in version v1.
- inputs:
Time in Zone,Detections Consensus,Detection Offset,Time in Zone,Detections Filter,Instance Segmentation Model,Detections Transformation,Time in Zone,Detections Stitch,SAM 3,Detections Combine,Dynamic Crop,Perspective Correction,Path Deviation,Detection Event Log,Instance Segmentation Model,Detections Classes Replacement,Detections Stabilizer,Bounding Rectangle,Line Counter,SAM 3,Dynamic Zone,Detections List Roll-Up,SAM 3,Velocity,Path Deviation,Seg Preview,Segment Anything 2 Model - outputs:
Detections Consensus,Detections Transformation,Time in Zone,Detections Stitch,Polygon Visualization,Dynamic Crop,Bounding Box Visualization,Model Monitoring Inference Aggregator,Roboflow Dataset Upload,Detection Event Log,Model Comparison Visualization,Camera Focus,Detections Classes Replacement,PTZ Tracking (ONVIF).md),Blur Visualization,Line Counter,Byte Tracker,Mask Visualization,Distance Measurement,Path Deviation,Roboflow Custom Metadata,Circle Visualization,Detections Merge,Trace Visualization,Pixelate Visualization,Color Visualization,Stability AI Inpainting,Size Measurement,Time in Zone,Byte Tracker,Dot Visualization,Detection Offset,Label Visualization,Time in Zone,Detections Filter,Florence-2 Model,Detections Combine,Perspective Correction,Halo Visualization,Crop Visualization,Ellipse Visualization,Path Deviation,Overlap Filter,Florence-2 Model,Detections Stabilizer,Bounding Rectangle,Corner Visualization,Line Counter,Dynamic Zone,Background Color Visualization,Roboflow Dataset Upload,Byte Tracker,Detections List Roll-Up,Velocity,Icon Visualization,Triangle Visualization,Segment Anything 2 Model
Input and Output Bindings¶
The available connections depend on its binding kinds. Check what binding kinds
Bounding Rectangle in version v1 has.
Bindings
-
input
predictions(instance_segmentation_prediction): Instance segmentation predictions containing polygon masks. The block requires masks to be present - it will raise an error if masks are missing. Each detection's polygon mask will be processed to calculate the minimum rotated bounding rectangle. The mask should contain polygon shapes that you want to convert to rectangular bounding boxes. Detections are processed individually, with the largest contour extracted from each mask. The block outputs detections with updated masks (rectangular), updated bounding boxes (axis-aligned boxes of the rotated rectangles), and additional rectangle metadata stored in detection.data (rectangle coordinates, width, height, angle)..
-
output
detections_with_rect(instance_segmentation_prediction): Prediction with detected bounding boxes and segmentation masks in form of sv.Detections(...) object.
Example JSON definition of step Bounding Rectangle in version v1
{
"name": "<your_step_name_here>",
"type": "roboflow_core/bounding_rect@v1",
"predictions": "$segmentation.predictions"
}