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
Provide an image to the
Image Anyinput.Define the reference area via the
Rectangleinput (two coordinates). Leave empty to use the entire image.Feed the candidate rectangle(s) to the
Rectanglesinput (single rectangle or a list).Run the scenario. Inspect the
Resultimage to see which rectangles are inside the reference area and useNot Empty,Count, andRectanglesoutputs 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 SelectorImage ROIto crop or pick the area visually before passing it to this block.For polygonal regions, consider using
Image ROI PolygonorCheck 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 Imageso you can open a larger viewer window.To record or archive results, send the
Resultoutput toImage LoggerorImage Writeto save annotated images when matches occur.If detection returns unexpected rectangles, preprocess the image with
Blur,Image Threshold, orHSV Filterto 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 ROIorImage ROI Selectto 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 Inputor logging blocks to inspect intermediate rectangle lists if results are unexpected.
Last updated
Was this helpful?