1 | initial version |
add a mouse callback to your window.
cv2.setMouseCallback('image',mousecallback)
in the callback function, run a point in polygon (cv.pointPolygonTest) test for each contour
def mousecallback(event,x,y,flags,param):
if event == cv2.EVENT_LBUTTONCLK:
for i in range(0,contours.size)
r=cv.pointPolygonTest(contour[i],Point(y,x),False)
if r>0:
print("Selected contour "+i)
I hope you get the idea. Note that the code is untested.
P.S. you might also use the path.contains_points()
from the Matplotlib library. Check the mouse handling tutorial in opencv too!