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:
Crop Visualization,Detection Event Log,Image Slicer,Roboflow Dataset Upload,ByteTrack Tracker,Instance Segmentation Model,Google Gemini,Classification Label Visualization,Mask Edge Snap,Dynamic Crop,Per-Class Confidence Filter,Detections Transformation,Time in Zone,SAM 3 Interactive,Velocity,Image Slicer,Absolute Static Crop,Detections Classes Replacement,Template Matching,Current Time,Pixel Color Count,Roboflow Custom Metadata,Multi-Label Classification Model,SIFT Comparison,Mask Area Measurement,Morphological Transformation,Background Subtraction,BoT-SORT Tracker,Line Counter Visualization,Ellipse Visualization,OpenAI,MoonshotAI Kimi,SAM 3,Grid Visualization,PLC ModbusTCP,Segment Anything 2 Model,Bounding Box Visualization,Morphological Transformation,Google Gemma,Byte Tracker,Object Detection Model,Motion Detection,Cosmos 3,Overlap Filter,OpenAI,Webhook Sink,VLM As Detector,Path Deviation,Size Measurement,Depth Estimation,Image Preprocessing,OPC UA Writer Sink,Bounding Rectangle,Detections Stabilizer,SAM 3,Line Counter,Stitch Images,Roboflow Dataset Upload,OpenAI,SAM2 Video Tracker,Camera Calibration,Google Vision OCR,OpenAI,QR Code Generator,Florence-2 Model,Polygon Zone Visualization,Detection Offset,Contrast Equalization,SAM3 Video Tracker,VLM As Classifier,Detections List Roll-Up,Clip Comparison,Pixelate Visualization,SORT Tracker,Qwen 3.6 API,PLC Writer,CSV Formatter,Detections Stitch,Track Class Lock,Triangle Visualization,Stability AI Image Generation,Icon Visualization,Dot Visualization,Stability AI Outpainting,Byte Tracker,Keypoint Visualization,Relative Static Crop,Anthropic Claude,PP-OCR,Anthropic Claude,Image Stack,Roboflow Visual Search Classifier,VLM As Detector,OCR Model,SAM 3,GeoTag Detection,PTZ Tracking (ONVIF),Qwen 3.5 API,Halo Visualization,OpenRouter,Frame Delay,Local File Sink,Text Display,Roboflow Asset Library Attributes,Image Threshold,Image Blur,LMM,Color Visualization,Corner Visualization,JSON Parser,S3 Sink,MQTT Writer,Qwen-VL,Instance Segmentation Model,Google Gemini,Stitch OCR Detections,Slack Notification,Event Writer,Detections Consensus,Identify Outliers,SIFT,Nearest Neighbor Detection Match,Stitch OCR Detections,Auto Rotate on Edges,Time in Zone,Google Gemini,VLM As Classifier,Instance Segmentation Model,Dimension Collapse,Twilio SMS Notification,Trace Visualization,Single-Label Classification Model,Perspective Correction,Seg Preview,EasyOCR,Camera Focus,Google Gemma API,PLC EthernetIP,Object Detection Model,Instance Segmentation Model,OC-SORT Tracker,MoonshotAI Kimi,Distance Measurement,Twilio SMS/MMS Notification,Path Deviation,Blur Visualization,LMM For Classification,Polygon Visualization,Model Monitoring Inference Aggregator,Stability AI Inpainting,Image Convert Grayscale,Microsoft SQL Server Sink,Florence-2 Model,Qwen3.5-VL,Moondream2,Clip Comparison,Dynamic Zone,Mask Visualization,Reference Path Visualization,Email Notification,Polygon Visualization,Roboflow Visual Search,SIFT Comparison,Halo Visualization,Contrast Enhancement,Llama 3.2 Vision,Detections Combine,GLM-OCR,CogVLM,Byte Tracker,Circle Visualization,Image Contours,Camera Focus,Heatmap Visualization,Line Counter,Roboflow Vision Events,YOLO-World Model,Llama 3.2 Vision,OpenAI-Compatible LLM,Label Visualization,Time in Zone,Background Color Visualization,Keypoint Detection Model,PLC Reader,Buffer,Model Comparison Visualization,Detections Merge,Detections Filter,Object Detection Model,Email Notification,Anthropic Claude,Identify Changes - outputs:
Crop Visualization,Detection Event Log,Image Slicer,Roboflow Dataset Upload,ByteTrack Tracker,Instance Segmentation Model,Google Gemini,Classification Label Visualization,Mask Edge Snap,Dynamic Crop,SAM 3 Interactive,Detections Transformation,Time in Zone,Per-Class Confidence Filter,Velocity,Image Slicer,Absolute Static Crop,Detections Classes Replacement,Overlap Analysis,Template Matching,Pixel Color Count,Roboflow Custom Metadata,Multi-Label Classification Model,SIFT Comparison,Mask Area Measurement,Morphological Transformation,Background Subtraction,BoT-SORT Tracker,Line Counter Visualization,Ellipse Visualization,MoonshotAI Kimi,Multi-Label Classification Model,OpenAI,SAM 3,Grid Visualization,Segment Anything 2 Model,Bounding Box Visualization,Morphological Transformation,Google Gemma,Semantic Segmentation Model,Perception Encoder Embedding Model,Byte Tracker,Object Detection Model,Cosmos 3,Motion Detection,Overlap Filter,OpenAI,Multi-Label Classification Model,Webhook Sink,VLM As Detector,Path Deviation,Size Measurement,Depth Estimation,Image Preprocessing,OPC UA Writer Sink,Detections Stabilizer,Bounding Rectangle,Single-Label Classification Model,SAM 3,QR Code Detection,Stitch Images,Roboflow Dataset Upload,OpenAI,SAM2 Video Tracker,Qwen3.5,Camera Calibration,Google Vision OCR,OpenAI,QR Code Generator,Florence-2 Model,Qwen3-VL,Polygon Zone Visualization,Detection Offset,Contrast Equalization,SAM3 Video Tracker,VLM As Classifier,Detections List Roll-Up,Clip Comparison,Pixelate Visualization,SORT Tracker,Qwen 3.6 API,Detections Stitch,Track Class Lock,Triangle Visualization,Stability AI Image Generation,Icon Visualization,Dot Visualization,Stability AI Outpainting,Byte Tracker,Keypoint Visualization,Anthropic Claude,Relative Static Crop,PP-OCR,Anthropic Claude,Image Stack,Roboflow Visual Search Classifier,VLM As Detector,OCR Model,SAM 3,GeoTag Detection,PTZ Tracking (ONVIF),Qwen 3.5 API,Halo Visualization,OpenRouter,Frame Delay,Semantic Segmentation Model,Text Display,Image Threshold,Image Blur,Gaze Detection,Color Visualization,LMM,Corner Visualization,MQTT Writer,Qwen-VL,Instance Segmentation Model,CLIP Embedding Model,Google Gemini,Stitch OCR Detections,Slack Notification,Event Writer,Detections Consensus,Identify Outliers,SIFT,Nearest Neighbor Detection Match,Stitch OCR Detections,VLM As Classifier,Time in Zone,Google Gemini,Auto Rotate on Edges,Instance Segmentation Model,Twilio SMS Notification,Trace Visualization,Single-Label Classification Model,Perspective Correction,Seg Preview,Camera Focus,EasyOCR,Google Gemma API,Object Detection Model,Instance Segmentation Model,OC-SORT Tracker,MoonshotAI Kimi,Distance Measurement,Twilio SMS/MMS Notification,Path Deviation,Blur Visualization,LMM For Classification,Polygon Visualization,Model Monitoring Inference Aggregator,Stability AI Inpainting,Image Convert Grayscale,Florence-2 Model,Qwen3.5-VL,Barcode Detection,Moondream2,Dominant Color,Clip Comparison,Dynamic Zone,Mask Visualization,Reference Path Visualization,Email Notification,Polygon Visualization,Roboflow Visual Search,Detections Filter,SIFT Comparison,Halo Visualization,SmolVLM2,Contrast Enhancement,Keypoint Detection Model,Llama 3.2 Vision,Detections Combine,GLM-OCR,CogVLM,Byte Tracker,Circle Visualization,Image Contours,Camera Focus,Heatmap Visualization,Roboflow Vision Events,Line Counter,Llama 3.2 Vision,YOLO-World Model,Qwen2.5-VL,Label Visualization,Time in Zone,Background Color Visualization,Keypoint Detection Model,Buffer,Single-Label Classification Model,Model Comparison Visualization,Keypoint Detection Model,Detections Merge,Line Counter,Object Detection Model,Email Notification,Anthropic Claude,Identify Changes
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
}