Shape Detector

This function block finds a distinct shape in a color image by filtering, thresholding and contour analysis. It returns a visualized result and numeric shape descriptors that can be used by downstream blocks.

πŸ“₯ Inputs

Image This input socket accepts a color image to analyze.

πŸ“€ Outputs

Filtered Image Output socket that provides the binary or filtered image used for contour extraction (visual feedback for preprocessing).

Contoured Image Output socket that provides the original image with detected contour drawn.

Shape Image Output socket that provides the cropped or separated shape visualization.

Border Coordinate Output socket that provides the contour coordinate(s) that form the detected border.

Shape Width Output socket that provides the detected shape width.

Shape Height Output socket that provides the detected shape height.

Shape Position Output socket that provides the detected shape center position.

Shape Rotation Output socket that provides the detected shape rotation angle.

πŸ•ΉοΈ Controls

Blur coefficient Slider control to tune median blur strength before thresholding. Use to reduce noise while preserving edges.

Clear spots parameter Slider control to set morphological closing size. Use to remove small holes or join object parts.

Auto threshold ? Checkbox control to enable automatic thresholding (Otsu). When enabled, manual threshold range is disabled.

Threshold range Two-ended slider control to set manual threshold low/high values. Active when Auto threshold ? is unchecked.

Shape area range % Two-ended slider control to limit detected contours by relative area (percentage of image). Use to ignore very small or very large objects.

βš™οΈ Running mechanism

  • When an image is provided to the Image input socket, the block applies the selected blur, thresholding (auto or manual) and morphological closing.

  • Contours are extracted from the filtered image. The block selects contours that fall into the configured Shape area range % and returns the largest valid contour and related outputs.

  • Visual outputs show the filtered image and the detected contour drawn on the original image so you can verify results in the UI.

  • Toggling Auto threshold ? instantly enables or disables the manual Threshold range control to let you experiment quickly.

✨ Features

  • Visual debugging outputs for both the thresholded image and contour overlay.

  • Flexible preprocessing: median blur and morphological closing parameters.

  • Area-based filtering to avoid false contours from noise or borders.

  • Produces both visual outputs and numeric descriptors (size, position, rotation) for downstream logic or logging.

πŸ“ Usage instructions

  1. Feed a color image into the Image input socket.

  2. Start with moderate Blur coefficient and a small Clear spots parameter.

  3. Try Auto threshold ? first. If results are noisy, uncheck and tune Threshold range manually.

  4. Adjust Shape area range % so the desired object falls within the allowed area window.

  5. Inspect Filtered Image and Contoured Image to confirm detection. Use downstream blocks to act on Shape Position or Shape Rotation.

πŸ’‘ Tips and Tricks

  • If the image has color noise or lighting variations, try adding a preprocessing chain before this block with HSV Filter or Adjust Colors to improve separation of the object from background.

  • Use Blur or Denoising upstream to reduce speckle before thresholding for more stable contours.

  • If you need to analyze only a sub-region, crop first with Image ROI Select or Image ROI and feed the cropped image into this block.

  • To convert a noisy color scene into a clearer binary input, combine with Image Adaptive Threshold or Image Threshold before this block.

  • For further geometric processing or feature extraction, connect outputs to related shape analysis blocks such as Approximate Contour, Minimum Rectangle, Minimum Rotated Rectangle or Translate Shape.

  • Visualize results live using the Show Image block and save examples or logs with Image Logger or Image Write for later inspection.

πŸ› οΈ Troubleshooting

  • No contour found: increase the upper bound of Shape area range % or lower the minimum; check Filtered Image to confirm the object appears after thresholding.

  • Too many small contours: increase Clear spots parameter (morphological closing) or tighten the minimum area in Shape area range %.

  • Object split into multiple contours: reduce blur or decrease morphological closing, or crop region with Image ROI Select to isolate the object.

  • Threshold not working: try enabling Auto threshold ? to let the block pick a suitable threshold automatically, then fine-tune the manual Threshold range if needed.

Last updated

Was this helpful?