Perspective Correction¶
Class: PerspectiveCorrectionBlockV1
Transform detection coordinates and optionally images from a perspective view to a top-down orthographic view using perspective transformation, correcting camera angle distortions to enable accurate measurements, top-down analysis, and coordinate normalization for scenarios where objects are viewed at an angle (e.g., surveillance cameras, aerial imagery, or tilted camera setups).
How This Block Works¶
This block corrects perspective distortion by transforming coordinates from a perspective view (where objects appear smaller when further away and angles are distorted) to a top-down orthographic view (as if the camera were directly above the scene). The block:
- Receives input data: images and/or detections (object detection or instance segmentation predictions), along with perspective polygons defining regions to transform
- Processes perspective polygons:
- Selects the largest polygon from provided polygons (if multiple are provided)
- Sorts polygon vertices in clockwise order and orients them starting from the leftmost bottom vertex
- Ensures proper polygon ordering for transformation matrix calculation
- Optionally extends perspective polygons to contain all detections:
- If
extend_perspective_polygon_by_detections_anchoris set, extends the polygon to ensure all detection anchor points (or entire bounding boxes if "ALL" is specified) are contained within the polygon - Calculates extension amounts needed to contain detections outside the original polygon
- Adjusts polygon vertices to create a larger region that encompasses all detections
- Generates perspective transformation matrix:
- Maps the source polygon (4 vertices in the perspective view) to a destination rectangle (top-down view) with specified width and height
- Uses OpenCV's
getPerspectiveTransformto compute the 3x3 transformation matrix - Handles extended dimensions when polygon extension is enabled
- Applies perspective transformation to detections (if provided):
- Transforms bounding box coordinates from perspective view to top-down coordinates
- Transforms instance segmentation masks by converting masks to polygons, transforming polygon vertices, and converting back to masks in the new coordinate space
- Transforms keypoint coordinates for keypoint detection predictions
- Updates all coordinate data to reflect the corrected perspective
- Optionally warps images (if
warp_imageis True): - Applies the perspective transformation to the entire image using OpenCV's
warpPerspective - Produces a top-down view of the image with corrected perspective
- Outputs the warped image at the specified transformed rectangle dimensions (plus any extensions)
- Returns corrected outputs:
corrected_coordinates: Detections with transformed coordinates in the top-down coordinate spacewarped_image: Perspective-corrected image (if image warping is enabled)extended_transformed_rect_widthandextended_transformed_rect_height: Final dimensions including any polygon extensions
The transformation effectively "unwarps" the perspective distortion, making coordinates and images appear as if viewed from directly above. This is useful for accurate measurements, area calculations, distance measurements, and spatial analysis where perspective distortion would otherwise introduce errors.
Common Use Cases¶
- Top-Down Analysis: Correct perspective distortion for top-down analysis and measurement (e.g., surveillance camera analysis, overhead view generation, top-down coordinate normalization), enabling top-down analysis workflows
- Accurate Measurements: Enable accurate distance, area, and size measurements by removing perspective distortion (e.g., measure object sizes in real-world units, calculate areas accurately, measure distances without distortion), enabling measurement workflows
- Spatial Analysis: Perform spatial analysis and coordinate-based operations on corrected coordinates (e.g., zone-based analysis, spatial tracking, coordinate-based filtering), enabling spatial analysis workflows
- Aerial and Overhead Imagery: Process aerial imagery or overhead camera feeds with perspective correction (e.g., drone imagery analysis, overhead camera processing, satellite image analysis), enabling aerial analysis workflows
- Quality Control and Inspection: Correct perspective for quality control and inspection workflows (e.g., manufacturing inspection, product quality checks, defect detection with accurate measurements), enabling quality control workflows
- Indoor Navigation and Mapping: Correct perspective for indoor navigation and mapping applications (e.g., floor plan generation, indoor mapping, navigation systems), enabling mapping workflows
Connecting to Other Blocks¶
This block receives images and/or detections and produces perspective-corrected outputs:
- After detection models to correct coordinates for accurate analysis (e.g., object detection with perspective correction, instance segmentation with corrected coordinates), enabling detection-to-correction workflows
- After zone or polygon definition blocks to use defined regions as perspective polygons (e.g., use polygon zones as perspective regions, apply correction to specific regions), enabling zone-to-correction workflows
- Before measurement blocks to enable accurate measurements on corrected coordinates (e.g., distance measurement with corrected coordinates, size measurement on top-down view, area calculation on corrected coordinates), enabling correction-to-measurement workflows
- Before analytics blocks to perform analytics on corrected coordinates (e.g., zone analytics with corrected coordinates, tracking with top-down view, path analysis with corrected paths), enabling correction-to-analytics workflows
- Before visualization blocks to visualize corrected coordinates and warped images (e.g., display top-down view, visualize corrected detections, show perspective-corrected results), enabling correction-to-visualization workflows
- In workflow outputs to provide perspective-corrected final outputs (e.g., top-down coordinate outputs, corrected detection outputs, warped image outputs), enabling correction-to-output workflows
Requirements¶
This block requires either images or predictions (detections) as input. The perspective_polygons parameter must contain at least one polygon with exactly 4 vertices defining the region to transform. Polygons can be provided as a list of 4 coordinate pairs [[x1, y1], [x2, y2], [x3, y3], [x4, y4]] or as NumPy arrays. If multiple polygons are provided, the largest polygon (by area) is selected for each batch element. The transformed_rect_width and transformed_rect_height parameters define the dimensions of the output top-down rectangle. The block uses OpenCV's perspective transformation functions, which require proper polygon ordering and valid coordinate data. If polygon extension is enabled, the output dimensions are automatically adjusted to include the extended regions.
Type identifier¶
Use the following identifier in step "type" field: roboflow_core/perspective_correction@v1to add the block as
as step in your workflow.
Properties¶
| Name | Type | Description | Refs |
|---|---|---|---|
name |
str |
Enter a unique identifier for this step.. | ❌ |
perspective_polygons |
List[Any] |
Perspective polygons defining regions to transform from perspective view to top-down view. Each polygon must consist of exactly 4 vertices (coordinates). Format: list of 4 coordinate pairs [[x1, y1], [x2, y2], [x3, y3], [x4, y4]] or NumPy arrays. If multiple polygons are provided for a batch element, the largest polygon (by area) is selected. The polygon defines the source region in the perspective view that will be mapped to the destination rectangle.. | ✅ |
transformed_rect_width |
int |
Width of the destination rectangle in the top-down view (in pixels). The perspective polygon is transformed to fit this width. Coordinates are scaled to match this dimension. If polygon extension is enabled, the actual output width may be larger to accommodate extended regions.. | ✅ |
transformed_rect_height |
int |
Height of the destination rectangle in the top-down view (in pixels). The perspective polygon is transformed to fit this height. Coordinates are scaled to match this dimension. If polygon extension is enabled, the actual output height may be larger to accommodate extended regions.. | ✅ |
extend_perspective_polygon_by_detections_anchor |
str |
Optional setting to extend the perspective polygon to contain all detection anchor points. If set to a Position value (CENTER, CENTER_LEFT, CENTER_RIGHT, TOP_CENTER, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT, CENTER_OF_MASS), extends the polygon to contain that anchor point from all detections. If set to 'ALL', extends to contain entire bounding boxes (all corners). Empty string (default) disables extension. Extension ensures all detections are within the transformed region, automatically adjusting polygon boundaries and output dimensions.. | ✅ |
warp_image |
bool |
If True, applies perspective transformation to the input image, producing a warped image in the top-down view. The warped image shows the perspective-corrected view at the specified transformed rectangle dimensions (plus any extensions). If False (default), only detection coordinates are transformed, and the original image is returned unchanged. Images must be provided if this is True.. | ✅ |
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 Perspective Correction in version v1.
- inputs:
Detections Filter,Absolute Static Crop,VLM As Classifier,Qwen-VL,Byte Tracker,Triangle Visualization,EasyOCR,Model Comparison Visualization,Detection Event Log,Stitch OCR Detections,Track Class Lock,YOLO-World Model,OC-SORT Tracker,Llama 3.2 Vision,Heatmap Visualization,Stitch Images,Keypoint Visualization,Anthropic Claude,Webhook Sink,Detections Stabilizer,Google Gemini,GLM-OCR,QR Code Generator,Instance Segmentation Model,VLM As Detector,SAM2 Video Tracker,PLC ModbusTCP,Multi-Label Classification Model,Line Counter,Twilio SMS/MMS Notification,Distance Measurement,Ellipse Visualization,Pixelate Visualization,Detections Transformation,Corner Visualization,Buffer,Template Matching,Bounding Rectangle,Llama 3.2 Vision,JSON Parser,Qwen 3.5 API,Per-Class Confidence Filter,Velocity,LMM,Roboflow Visual Search,OpenAI-Compatible LLM,Morphological Transformation,Color Visualization,Roboflow Dataset Upload,Dimension Collapse,Morphological Transformation,Camera Calibration,Motion Detection,Detection Offset,Google Vision OCR,Clip Comparison,Bounding Box Visualization,OpenAI,Halo Visualization,SAM3 Video Tracker,Object Detection Model,Detections Combine,Identify Changes,Contrast Equalization,CSV Formatter,Mask Area Measurement,Detections Classes Replacement,Instance Segmentation Model,Model Monitoring Inference Aggregator,MQTT Writer,PLC Reader,Image Threshold,Blur Visualization,Line Counter Visualization,Google Gemini,Microsoft SQL Server Sink,Single-Label Classification Model,Background Subtraction,VLM As Classifier,Object Detection Model,Identify Outliers,Path Deviation,Instance Segmentation Model,SAM 3,Polygon Zone Visualization,Twilio SMS Notification,Google Gemma API,OPC UA Writer Sink,Reference Path Visualization,Image Stack,SAM 3 Interactive,Stability AI Inpainting,Crop Visualization,Anthropic Claude,Dynamic Zone,Image Convert Grayscale,Camera Focus,Image Slicer,Overlap Filter,Florence-2 Model,Time in Zone,Polygon Visualization,MoonshotAI Kimi,Dynamic Crop,Qwen 3.6 API,Event Writer,Perspective Correction,Segment Anything 2 Model,Line Counter,Polygon Visualization,Clip Comparison,OCR Model,Roboflow Visual Search Classifier,Circle Visualization,Slack Notification,CogVLM,Contrast Enhancement,PLC EthernetIP,Grid Visualization,Mask Edge Snap,Time in Zone,Byte Tracker,LMM For Classification,Florence-2 Model,OpenAI,Local File Sink,Roboflow Custom Metadata,SORT Tracker,Qwen3.5-VL,ByteTrack Tracker,Image Blur,Label Visualization,Seg Preview,Path Deviation,Object Detection Model,Anthropic Claude,Pixel Color Count,Roboflow Vision Events,Image Preprocessing,Trace Visualization,Email Notification,SIFT Comparison,Stability AI Outpainting,Detections Consensus,PTZ Tracking (ONVIF),Dot Visualization,Current Time,Keypoint Detection Model,Roboflow Asset Library Attributes,Halo Visualization,SAM 3,Classification Label Visualization,Mask Visualization,Image Contours,Camera Focus,OpenRouter,Moondream2,S3 Sink,Stability AI Image Generation,VLM As Detector,Google Gemma,Relative Static Crop,Roboflow Dataset Upload,OpenAI,Image Slicer,Detections Merge,Stitch OCR Detections,Google Gemini,BoT-SORT Tracker,Email Notification,Byte Tracker,SAM 3,Detections Stitch,Text Display,Size Measurement,Depth Estimation,Icon Visualization,OpenAI,Time in Zone,GeoTag Detection,PLC Writer,SIFT Comparison,SIFT,Instance Segmentation Model,Background Color Visualization,Detections List Roll-Up,MoonshotAI Kimi - outputs:
Detections Filter,Absolute Static Crop,VLM As Classifier,Qwen-VL,Gaze Detection,Triangle Visualization,Byte Tracker,EasyOCR,Model Comparison Visualization,Detection Event Log,Stitch OCR Detections,OC-SORT Tracker,Track Class Lock,YOLO-World Model,Llama 3.2 Vision,Heatmap Visualization,Anthropic Claude,Stitch Images,Keypoint Visualization,Webhook Sink,Detections Stabilizer,Google Gemini,Dominant Color,MoonshotAI Kimi,GLM-OCR,Instance Segmentation Model,VLM As Detector,QR Code Generator,SAM2 Video Tracker,Multi-Label Classification Model,Twilio SMS/MMS Notification,Line Counter,Distance Measurement,Ellipse Visualization,Single-Label Classification Model,SmolVLM2,Keypoint Detection Model,Pixelate Visualization,Detections Transformation,Corner Visualization,Overlap Analysis,Buffer,Template Matching,Bounding Rectangle,Llama 3.2 Vision,Qwen2.5-VL,Qwen 3.5 API,Velocity,Per-Class Confidence Filter,LMM,Semantic Segmentation Model,Roboflow Visual Search,Morphological Transformation,Color Visualization,Roboflow Dataset Upload,Morphological Transformation,Camera Calibration,Motion Detection,Detection Offset,Google Vision OCR,Clip Comparison,Bounding Box Visualization,OpenAI,Halo Visualization,SAM3 Video Tracker,Detections Combine,Object Detection Model,Identify Changes,Contrast Equalization,Mask Area Measurement,Detections Classes Replacement,Instance Segmentation Model,Model Monitoring Inference Aggregator,Multi-Label Classification Model,MQTT Writer,Image Threshold,Blur Visualization,Line Counter Visualization,Google Gemini,Single-Label Classification Model,Background Subtraction,VLM As Classifier,Object Detection Model,Identify Outliers,Path Deviation,Instance Segmentation Model,SAM 3,QR Code Detection,Polygon Zone Visualization,Google Gemma API,OPC UA Writer Sink,Twilio SMS Notification,Keypoint Detection Model,Image Stack,Reference Path Visualization,SAM 3 Interactive,Qwen3-VL,Stability AI Inpainting,Multi-Label Classification Model,Perception Encoder Embedding Model,Crop Visualization,Anthropic Claude,Dynamic Zone,Image Convert Grayscale,Camera Focus,Image Slicer,Overlap Filter,Florence-2 Model,Time in Zone,Polygon Visualization,MoonshotAI Kimi,Dynamic Crop,Qwen 3.6 API,Event Writer,Perspective Correction,Segment Anything 2 Model,Line Counter,Polygon Visualization,Clip Comparison,OCR Model,Roboflow Visual Search Classifier,Circle Visualization,Slack Notification,CogVLM,Contrast Enhancement,Grid Visualization,Mask Edge Snap,Time in Zone,Byte Tracker,Barcode Detection,Florence-2 Model,LMM For Classification,Qwen3.5-VL,Roboflow Custom Metadata,SORT Tracker,OpenAI,ByteTrack Tracker,Label Visualization,Image Blur,Seg Preview,Path Deviation,Object Detection Model,Anthropic Claude,Pixel Color Count,Roboflow Vision Events,Image Preprocessing,Trace Visualization,Email Notification,SIFT Comparison,Stability AI Outpainting,Detections Consensus,PTZ Tracking (ONVIF),Dot Visualization,Keypoint Detection Model,Halo Visualization,SAM 3,Classification Label Visualization,Image Contours,Camera Focus,Single-Label Classification Model,OpenRouter,Moondream2,Stability AI Image Generation,VLM As Detector,Google Gemma,Roboflow Dataset Upload,CLIP Embedding Model,Relative Static Crop,OpenAI,Image Slicer,Detections Merge,Stitch OCR Detections,Google Gemini,BoT-SORT Tracker,Email Notification,Byte Tracker,SAM 3,Detections Stitch,Semantic Segmentation Model,Text Display,Size Measurement,Qwen3.5,Depth Estimation,Icon Visualization,OpenAI,Time in Zone,GeoTag Detection,SIFT Comparison,SIFT,Instance Segmentation Model,Background Color Visualization,Detections List Roll-Up,Mask Visualization
Input and Output Bindings¶
The available connections depend on its binding kinds. Check what binding kinds
Perspective Correction in version v1 has.
Bindings
-
input
predictions(Union[instance_segmentation_prediction,object_detection_prediction]): Optional object detection or instance segmentation predictions to transform. If provided, bounding boxes, masks, and keypoints are transformed to the top-down coordinate space. If not provided, only image warping is performed (if enabled). Either predictions or images must be provided..images(image): Input images to optionally warp to top-down view. Required if warp_image is True. Images are transformed using the perspective transformation matrix to produce top-down views. If only images are provided (no predictions), only image warping is performed..perspective_polygons(list_of_values): Perspective polygons defining regions to transform from perspective view to top-down view. Each polygon must consist of exactly 4 vertices (coordinates). Format: list of 4 coordinate pairs [[x1, y1], [x2, y2], [x3, y3], [x4, y4]] or NumPy arrays. If multiple polygons are provided for a batch element, the largest polygon (by area) is selected. The polygon defines the source region in the perspective view that will be mapped to the destination rectangle..transformed_rect_width(integer): Width of the destination rectangle in the top-down view (in pixels). The perspective polygon is transformed to fit this width. Coordinates are scaled to match this dimension. If polygon extension is enabled, the actual output width may be larger to accommodate extended regions..transformed_rect_height(integer): Height of the destination rectangle in the top-down view (in pixels). The perspective polygon is transformed to fit this height. Coordinates are scaled to match this dimension. If polygon extension is enabled, the actual output height may be larger to accommodate extended regions..extend_perspective_polygon_by_detections_anchor(string): Optional setting to extend the perspective polygon to contain all detection anchor points. If set to a Position value (CENTER, CENTER_LEFT, CENTER_RIGHT, TOP_CENTER, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT, CENTER_OF_MASS), extends the polygon to contain that anchor point from all detections. If set to 'ALL', extends to contain entire bounding boxes (all corners). Empty string (default) disables extension. Extension ensures all detections are within the transformed region, automatically adjusting polygon boundaries and output dimensions..warp_image(boolean): If True, applies perspective transformation to the input image, producing a warped image in the top-down view. The warped image shows the perspective-corrected view at the specified transformed rectangle dimensions (plus any extensions). If False (default), only detection coordinates are transformed, and the original image is returned unchanged. Images must be provided if this is True..
-
output
corrected_coordinates(Union[object_detection_prediction,instance_segmentation_prediction]): Prediction with detected bounding boxes in form of sv.Detections(...) object ifobject_detection_predictionor Prediction with detected bounding boxes and segmentation masks in form of sv.Detections(...) object ifinstance_segmentation_prediction.warped_image(image): Image in workflows.extended_transformed_rect_width(integer): Integer value.extended_transformed_rect_height(integer): Integer value.
Example JSON definition of step Perspective Correction in version v1
{
"name": "<your_step_name_here>",
"type": "roboflow_core/perspective_correction@v1",
"predictions": "$steps.object_detection_model.predictions",
"images": "$inputs.image",
"perspective_polygons": "$steps.perspective_wrap.zones",
"transformed_rect_width": 1000,
"transformed_rect_height": 1000,
"extend_perspective_polygon_by_detections_anchor": "CENTER",
"warp_image": false
}