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:
SAM 3,Segment Anything 2 Model,Time in Zone,Mask Edge Snap,Line Counter,Path Deviation,Path Deviation,Per-Class Confidence Filter,Instance Segmentation Model,SAM2 Video Tracker,Instance Segmentation Model,Dynamic Zone,Detections Combine,Seg Preview,Bounding Rectangle,Dynamic Crop,SAM 3,Detections Transformation,BoT-SORT Tracker,SAM 3 Interactive,OC-SORT Tracker,Velocity,Mask Area Measurement,Detections Stitch,Detection Offset,Track Class Lock,SORT Tracker,Perspective Correction,Time in Zone,Instance Segmentation Model,Detection Event Log,Detections Consensus,ByteTrack Tracker,Detections List Roll-Up,Detections Filter,Detections Stabilizer,Detections Classes Replacement,SAM 3,SAM3 Video Tracker,Time in Zone,Instance Segmentation Model - outputs:
Size Measurement,Circle Visualization,Path Deviation,Path Deviation,Overlap Filter,PTZ Tracking (ONVIF),Event Writer,SAM2 Video Tracker,Halo Visualization,Bounding Rectangle,Dot Visualization,Byte Tracker,Label Visualization,Background Color Visualization,SAM 3 Interactive,Velocity,Pixelate Visualization,Mask Area Measurement,Heatmap Visualization,Track Class Lock,Time in Zone,Trace Visualization,Blur Visualization,Detection Event Log,ByteTrack Tracker,Camera Focus,Detections List Roll-Up,Florence-2 Model,Corner Visualization,Detections Stabilizer,Model Comparison Visualization,Model Monitoring Inference Aggregator,Byte Tracker,Polygon Visualization,Segment Anything 2 Model,Polygon Visualization,Time in Zone,Mask Edge Snap,Line Counter,Per-Class Confidence Filter,Icon Visualization,Color Visualization,Dynamic Zone,Detections Combine,Triangle Visualization,Roboflow Dataset Upload,Dynamic Crop,Stability AI Inpainting,BoT-SORT Tracker,Detections Transformation,Bounding Box Visualization,Crop Visualization,OC-SORT Tracker,Byte Tracker,Mask Visualization,Halo Visualization,Detections Stitch,Distance Measurement,Florence-2 Model,SORT Tracker,Perspective Correction,Detection Offset,Roboflow Vision Events,Overlap Analysis,Roboflow Dataset Upload,Detections Consensus,Roboflow Custom Metadata,Detections Filter,Ellipse Visualization,Detections Merge,Detections Classes Replacement,Line Counter,Time in Zone
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"
}