Reputation: 351
I have various contours/segments in an image. Right now I use the keyboard to input which segment I want to extract from the image (given below)
Consider the pink area as segment 1 and white area as segment 2. I use keyboard to input which segment(1 or 2) I want extracted.On drawing contour I get
I have saved the colours of each segments in an array and I use the array to extract the particular segment.
Now I want know if its possible to use mouse click to identify the segment/contour, So that I can draw multiple contours and identify the segment using mouse and not use keyboard to input the segment number.
Upvotes: 1
Views: 1430
Reputation: 2935
I know this question was asked a while ago, but this is what I did to solve my problem. I was doing it in python, but it should be similar.
I used the OpenCV floodfill algorithm to fill where I clicked, using the drawn contours on a binary image as the floodfill mask, where the contours are white and background is black. This way the floodfill cannot pass the contour edges.
Once you fill the contour with a certain color, it's easy to extract it using some sort of thresholding.
Hope this helps.
Upvotes: 2