Image Contours¶
Class: ImageContoursDetectionBlockV1
Source: inference.core.workflows.core_steps.classical_cv.contours.v1.ImageContoursDetectionBlockV1
Detect and extract contours (boundaries of shapes) from a thresholded binary or grayscale image using OpenCV's contour detection, drawing the detected contours on the image, and returning contour data including coordinates, hierarchy information, and count for shape analysis, object boundary detection, and contour-based image processing workflows.
How This Block Works¶
This block detects contours (connected boundaries of shapes) in an image and draws them for visualization. The block:
- Receives an input image that should be thresholded (binary or grayscale) for best results
- Converts the image to grayscale if it's in color (handles BGR color images by converting to grayscale)
- Detects contours using OpenCV's findContours function:
- Uses RETR_EXTERNAL retrieval mode to find only external contours (outer boundaries of shapes)
- Uses CHAIN_APPROX_SIMPLE approximation method to compress contour points (reduces redundant points)
- Detects all connected boundary points that form closed or open contours
- Returns contours as arrays of points and hierarchy information describing contour relationships
- Draws detected contours on the image:
- Converts the grayscale image back to BGR color format for visualization
- Draws all contours on the image using a configurable line thickness
- Uses purple color (255, 0, 255 in BGR) by default for contour lines
- Draws contours directly on the image for visual inspection
- Counts the total number of contours detected in the image
- Returns the image with contours drawn, the contours data (point arrays), hierarchy information, and the contour count
The block expects a thresholded (binary) image where objects are white and background is black (or vice versa) for optimal contour detection. Contours are detected as the boundaries between different pixel intensity regions. The RETR_EXTERNAL mode focuses on outer boundaries, ignoring internal holes, which is useful for detecting separate objects. The CHAIN_APPROX_SIMPLE method simplifies contours by removing redundant points along straight lines, making the contour data more compact while preserving essential shape information.
Common Use Cases¶
- Shape Detection and Analysis: Detect and analyze shapes in images by finding their boundaries (e.g., detect object boundaries for shape analysis, identify geometric shapes, extract shape outlines for measurement), enabling shape-based image analysis workflows
- Object Boundary Extraction: Extract object boundaries and outlines from thresholded images (e.g., extract object boundaries for further processing, identify object edges, detect object outlines in binary images), enabling boundary extraction workflows
- Image Segmentation Analysis: Analyze segmentation results by detecting contour boundaries (e.g., find contours from segmentation masks, analyze segmented regions, extract boundaries from segmented objects), enabling segmentation analysis workflows
- Quality Control and Inspection: Use contour detection for quality control and inspection tasks (e.g., detect defects by finding unexpected contours, verify object shapes, inspect object boundaries), enabling contour-based quality control workflows
- Object Counting: Count objects in images by detecting their contours (e.g., count objects by detecting contours, enumerate objects based on boundaries, quantify items using contour detection), enabling contour-based object counting workflows
- Measurement and Analysis: Use contours for measurements and geometric analysis (e.g., measure object perimeters using contours, analyze object shapes, calculate geometric properties from contours), enabling contour-based measurement workflows
Connecting to Other Blocks¶
This block receives a thresholded image and produces contour data and visualizations:
- After image thresholding blocks to detect contours in thresholded binary images (e.g., find contours after thresholding, detect shapes in binary images, extract boundaries from thresholded images), enabling thresholding-to-contour workflows
- After image preprocessing blocks that prepare images for contour detection (e.g., detect contours after preprocessing, find shapes after filtering, extract boundaries after enhancement), enabling preprocessed contour detection workflows
- After segmentation blocks to extract contours from segmentation results (e.g., find contours from segmentation masks, detect boundaries of segmented regions, extract shape outlines from segments), enabling segmentation-to-contour workflows
- Before visualization blocks to display contour visualizations (e.g., visualize detected contours, display shape boundaries, show contour analysis results), enabling contour visualization workflows
- Before analysis blocks that process contour data (e.g., analyze contour shapes, process contour coordinates, measure contour properties), enabling contour analysis workflows
- Before filtering or logic blocks that use contour count or properties for decision-making (e.g., filter based on contour count, make decisions based on detected shapes, apply logic based on contour properties), enabling contour-based conditional workflows
Requirements¶
The input image should be thresholded (converted to binary/grayscale) before using this block. Thresholded images have distinct foreground (white) and background (black) regions, which makes contour detection more reliable. Use thresholding blocks (e.g., Image Threshold) or segmentation blocks to prepare images before contour detection.
Type identifier¶
Use the following identifier in step "type" field: roboflow_core/contours_detection@v1to add the block as
as step in your workflow.
Properties¶
| Name | Type | Description | Refs |
|---|---|---|---|
name |
str |
Enter a unique identifier for this step.. | ❌ |
line_thickness |
int |
Thickness of the lines used to draw contours on the output image. Must be a positive integer. Thicker lines (e.g., 5-10) make contours more visible but may obscure fine details. Thinner lines (e.g., 1-2) show more detail but may be harder to see. Default is 3, which provides good visibility. Adjust based on image size and desired visibility. Use thicker lines for large images or when contours need to be highly visible, thinner lines for detailed analysis or small images.. | ✅ |
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 Image Contours in version v1.
- inputs:
Stitch Images,Image Threshold,Stability AI Inpainting,Corner Visualization,Image Blur,Ellipse Visualization,Perspective Correction,Depth Estimation,Camera Calibration,Distance Measurement,Absolute Static Crop,Stability AI Image Generation,Grid Visualization,Background Color Visualization,Dynamic Crop,Template Matching,Image Slicer,Image Preprocessing,Relative Static Crop,Contrast Equalization,Background Subtraction,Morphological Transformation,Line Counter Visualization,SIFT,SIFT Comparison,Trace Visualization,Keypoint Visualization,Detection Event Log,Halo Visualization,Dot Visualization,Line Counter,Pixel Color Count,Pixelate Visualization,Circle Visualization,Image Convert Grayscale,Icon Visualization,QR Code Generator,Halo Visualization,Camera Focus,SIFT Comparison,Line Counter,Polygon Visualization,Color Visualization,Text Display,Reference Path Visualization,Crop Visualization,Mask Visualization,Heatmap Visualization,Triangle Visualization,Blur Visualization,Bounding Box Visualization,Label Visualization,Classification Label Visualization,Camera Focus,Polygon Visualization,Image Slicer,Image Contours,Model Comparison Visualization,Stability AI Outpainting,Polygon Zone Visualization - outputs:
Image Threshold,Email Notification,Corner Visualization,Roboflow Dataset Upload,Object Detection Model,Stitch OCR Detections,Gaze Detection,Stability AI Image Generation,Time in Zone,Grid Visualization,Dynamic Crop,Instance Segmentation Model,Image Slicer,Image Preprocessing,SIFT,Line Counter Visualization,Trace Visualization,Halo Visualization,ByteTrack Tracker,Pixelate Visualization,Circle Visualization,Semantic Segmentation Model,Detections Classes Replacement,Keypoint Detection Model,Twilio SMS Notification,Halo Visualization,SIFT Comparison,Anthropic Claude,OC-SORT Tracker,Polygon Visualization,Detections Consensus,Identify Changes,Qwen3-VL,Crop Visualization,Roboflow Dataset Upload,Mask Visualization,Detection Offset,CLIP Embedding Model,Heatmap Visualization,Webhook Sink,Google Vision OCR,Florence-2 Model,Florence-2 Model,VLM As Classifier,Anthropic Claude,OpenAI,VLM As Detector,OpenAI,PTZ Tracking (ONVIF),Template Matching,Background Color Visualization,Anthropic Claude,Background Subtraction,SIFT Comparison,Multi-Label Classification Model,Keypoint Visualization,Stitch OCR Detections,LMM,Identify Outliers,Perception Encoder Embedding Model,SAM 3,Motion Detection,Seg Preview,Single-Label Classification Model,Dynamic Zone,Object Detection Model,Roboflow Vision Events,VLM As Classifier,Detections Stitch,Triangle Visualization,Google Gemini,Image Slicer,Image Contours,Model Comparison Visualization,Stability AI Outpainting,Stitch Images,Image Blur,Ellipse Visualization,OpenAI,Barcode Detection,Depth Estimation,EasyOCR,Absolute Static Crop,Multi-Label Classification Model,CogVLM,Google Gemini,Relative Static Crop,Morphological Transformation,LMM For Classification,Dot Visualization,GLM-OCR,Keypoint Detection Model,Pixel Color Count,Image Convert Grayscale,Icon Visualization,QR Code Generator,Detections Stabilizer,Camera Focus,SAM 3,OCR Model,Text Display,Qwen2.5-VL,Reference Path Visualization,Instance Segmentation Model,Llama 3.2 Vision,SORT Tracker,Byte Tracker,Label Visualization,Byte Tracker,Classification Label Visualization,Segment Anything 2 Model,Polygon Zone Visualization,Stability AI Inpainting,Google Gemini,SAM 3,Perspective Correction,Camera Calibration,Qwen3.5-VL,Email Notification,Contrast Equalization,SmolVLM2,Single-Label Classification Model,Byte Tracker,Color Visualization,OpenAI,Dominant Color,QR Code Detection,Clip Comparison,YOLO-World Model,Buffer,Clip Comparison,Twilio SMS/MMS Notification,Bounding Box Visualization,Blur Visualization,Camera Focus,Polygon Visualization,Moondream2,VLM As Detector,Slack Notification
Input and Output Bindings¶
The available connections depend on its binding kinds. Check what binding kinds
Image Contours in version v1 has.
Bindings
-
input
image(image): Input image to detect contours from. Should be thresholded (binary or grayscale) for best results - thresholded images have distinct foreground and background regions that make contour detection more reliable. The image will be converted to grayscale automatically if it's in color format. Contours are detected as boundaries between different pixel intensity regions. Use thresholding blocks (e.g., Image Threshold) or segmentation blocks to prepare images before contour detection. The block detects external contours (outer boundaries) and draws them on the image..line_thickness(integer): Thickness of the lines used to draw contours on the output image. Must be a positive integer. Thicker lines (e.g., 5-10) make contours more visible but may obscure fine details. Thinner lines (e.g., 1-2) show more detail but may be harder to see. Default is 3, which provides good visibility. Adjust based on image size and desired visibility. Use thicker lines for large images or when contours need to be highly visible, thinner lines for detailed analysis or small images..
-
output
image(image): Image in workflows.contours(contours): List of numpy arrays where each array represents contour points.hierarchy(numpy_array): Numpy array.number_contours(integer): Integer value.
Example JSON definition of step Image Contours in version v1
{
"name": "<your_step_name_here>",
"type": "roboflow_core/contours_detection@v1",
"image": "$inputs.image",
"line_thickness": 3
}