1 | initial version |
I think the easiest is to create a mask for each contour, and then use the mean function to get the average color inside it.
If you create an empty one channel image the same size as your input, you can use drawContours to fill the area of the contour with 255. That is the mask to use with the mean function. Do this for each candidate, and there you go.