A robot vision check accepts detected points inside an L-shaped inspection region. A bounding box also includes the notch, where a detection may sit outside the usable surface. Even a point inside the outline may be too close to the edge if the next step needs room for a measurement window. Test the actual contour and compare the signed distance with the required margin.
OpenCV's pointPolygonTest can report membership or distance. In distance mode, the result is positive inside the supplied contour, negative outside it, and zero on its boundary. The magnitude measures distance to the nearest edge in the coordinates of that contour. For an outline authored in image coordinates, the distances are in pixels.
Check four points around the same notch
The polygon below has a rectangular cutout in its upper right. Four detections test a comfortable interior position, an interior position near the notch, a point in the cutout, and a point on the edge. The rule accepts a point with at least eight pixels of clearance.
import cv2 as cv
import numpy as np
outline = np.array(
[(10, 10), (60, 10), (60, 40), (100, 40), (100, 80), (10, 80)],
dtype=np.int32,
)
candidates = [(25, 25), (57, 25), (82, 32), (80, 40)]
minimum = 8.0
distances = [cv.pointPolygonTest(outline, xy, True) for xy in candidates]
accepted = [xy for xy, distance in zip(candidates, distances) if distance >= minimum]
assert np.allclose(distances, [15.0, 3.0, -8.0, 0.0])
assert accepted == [(25, 25)]
OpenCV 5.0.0 reports distances of 15, 3, -8, and zero pixels in that order. The first point passes. The second point is inside and falls five pixels short of the requested margin. The third lies inside the overall bounding box and lands outside the contour, in the notch. The fourth lies on the edge; the signed zero can print as -0.0 and still compares equal to zero.
Keep the detection and contour in the same coordinates
If a detector reports coordinates relative to a crop, add the crop offset before comparing them with a full-image contour. Apply the same geometric mapping to both when the image is resized or rectified. Write down the pixel margin, the contour version, and the frame or crop used to produce the measurement so another reviewer can reproduce it.
The single contour in this test describes a planar image region with an open notch. An enclosed hole needs separate handling, such as an additional exclusion contour or a mask that preserves the hole. If the real requirement is clearance for a physical tool, use calibrated geometry and evaluate the tool footprint and pose. This image test checks the center point against a two-dimensional outline.
Sources
OpenCV shape analysis reference for signed point-to-contour distance
https://docs.opencv.org/4.13.0/d3/dc0/group__imgproc__shape.html
OpenCV Point Polygon Test tutorial for applying the distance query to image coordinates
https://docs.opencv.org/4.13.0/dc/d48/tutorial_point_polygon_test.html