Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

opencv has pointPolygonTest for this:

Point mouse(x,y); // picked point
int hitId = -1; // id of picked contour

for (size_t i=0; i<contours.size(); i++) {
     if (pointPolygonTest(contours[i], mouse,false) > 0) {
         hitId = i;
         break;
    }
}

// there will still be the case, where you did **not** hit any contour, take care !

opencv has pointPolygonTest for this:

Point mouse(x,y); // picked point
int hitId = -1; // id of picked contour

for (size_t i=0; i<contours.size(); i++) {
     if (pointPolygonTest(contours[i], mouse,false) > 0) {
         hitId = i;
         break;
    }
}
 // now, you still might end up with hitId == -1
// there will still be the case, where you did **not** hit any contour, take care !