What's the most efficient way to select a non-rectangular ROI of an Image in OpenCV? What's the most efficient way to select a non-rectangular ROI of an Image in OpenCV? numpy numpy

What's the most efficient way to select a non-rectangular ROI of an Image in OpenCV?


Draw the mask with fillPoly:

mask = np.ones((1000, 2000))                              # (height, width)myROI = [(750, 0), (900, 1000), (1000, 1000), (1500, 0)]  # (x, y)cv2.fillPoly(mask, [np.array(myROI)], 0)

This should take ~1ms.