Hey OpenCV/Emgu gurus,
I have an image that I am generating contour for, see below. I am trying to generate a color histogram based pruning of search space of images to look for. How can I get the mask around just the prominent object contour and block out the remaining. So I have a 2 part question:
How do I "invert" the image outside the contour? Floodfill invert, not? I am confused with all the options in OpenCV.
Second, how do I generate a 1-d color histogram from the contoured object in this case the red car to exclude the black background and only generate the color histogram that includes the car.
How would I do that in OpenCV (preferably in Emgu/C# code)?
Perhaps something like this? Done using the Python bindings, but easy to translate the methods to other bindings...
This is a little bit clunky finding the mask - I wonder perhaps due to JPEG compression artefacts in the image... If you had the original contour it is easy enough to "render" this to a mask instead.
The example histogram rendering function is also a wee bit basic - but I think it shows the idea (and how the car is predominately red!). Note how OpenCV's interpretation of Hue ranges only from [0-180] degrees.
EDIT: if you want to use the mask to count colours in the original image - edit as so from line 15 downwards:
(I think this is more what was intended, as the mask is then derived separately and applied to a completely different image. The histogram is roughly the same in both cases...)