Rectangles in Rectangle

This function block checks whether one or more detected rectangles lie inside a reference rectangle (region of interest) on an image. It provides a visual result with colored rectangles and labels, a boolean indicating presence, a count of matches, and a list of the rectangles that are inside the reference area.

πŸ“₯ Inputs

Image Any Main image used for visualization and checks. The reference rectangle and candidate rectangles are drawn on this image for feedback.

Rectangle Reference rectangle defined by two corner points (top-left and bottom-right). If left empty, the full image area is used.

Rectangles One or multiple candidate rectangles to be checked against the reference rectangle. Accepts a list of coordinate pairs.

πŸ“€ Outputs

Result Annotated image showing the reference rectangle and all candidate rectangles. Rectangles inside the reference area are drawn in green and labeled OK; those outside are drawn in red and labeled NOK.

Not Empty Boolean that is True when at least one candidate rectangle is inside the reference rectangle.

Count Number of candidate rectangles that were found inside the reference rectangle.

Rectangles List of rectangle coordinates that were determined to be inside the reference rectangle.

πŸ•ΉοΈ Controls

No Controls This block does not require additional UI widgets; behavior is controlled entirely via its inputs (reference rectangle and candidate rectangles). Use other blocks or UI tools to create or edit rectangle inputs.

🎨 Features

  • Visual confirmation: the output image clearly shows the reference area and draws each candidate rectangle with color-coded status and text labels.

  • Flexible reference: you may provide an explicit reference rectangle or leave it empty to use the whole image as the reference.

  • Multiple rectangle support: accepts a single rectangle or a list of rectangles in one run.

  • Safe handling: checks and reports when inputs are invalid or out of image bounds.

πŸ“ Usage Instructions

  1. Provide an image to the Image Any input.

  2. Define the reference area via the Rectangle input (two coordinates). Leave empty to use the entire image.

  3. Feed the candidate rectangle(s) to the Rectangles input (single rectangle or a list).

  4. Run the scenario. Inspect the Result image to see which rectangles are inside the reference area and use Not Empty, Count, and Rectangles outputs for logic or logging.

πŸ“Š Evaluation

When evaluated, the block calculates whether each candidate rectangle's center lies inside the reference rectangle and whether the candidate rectangle fits (size-wise) within the reference. It returns an annotated image, a boolean presence flag, the number of matches, and a list of matched rectangles.

πŸ’‘ Tips and Tricks

  • Use Find Object (template matching) or similar detection blocks to generate candidate rectangles automatically, then feed those rectangles into this block for area filtering.

  • If you need a quick interactive way to create the reference area, combine with Image ROI Select or Image ROI to crop or pick the area visually before passing it to this block.

  • For polygonal regions, consider using Image ROI Polygon or Check Area (Polygon) in combination with this block. Use polygon-based blocks to get more precise region definitions, then convert or supply rectangle coordinates when needed.

  • To visualize or inspect results on-screen, follow this block with Show Image so you can open a larger viewer window.

  • To record or archive results, send the Result output to Image Logger or Image Write to save annotated images when matches occur.

  • If detection returns unexpected rectangles, preprocess the image with Blur, Image Threshold, or HSV Filter to improve upstream object detection quality.

πŸ› οΈ Troubleshooting

  • If no rectangles are detected as inside despite visual overlap, ensure the reference rectangle and candidate rectangles are provided in the expected coordinate format (two corner points each) and that coordinates fall within the image dimensions.

  • If candidate rectangles appear incorrectly labeled, confirm that the rectangle list input follows the correct nesting (a list of coordinate pairs) and try using Get ROI or Image ROI Select to produce well-formed rectangle coordinates.

  • If the output image looks unchanged, verify the image input contains the expected content and that candidate rectangle coordinates are not empty or None.

  • Use Debug Input or logging blocks to inspect intermediate rectangle lists if results are unexpected.

Last updated

Was this helpful?