Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Detect contour with mask

Hi all,

I'm detecting circular objects in an image by first getting a binary map based on color deviation from the background and then getting the contours of the connected components (and then a bunch of other stuff). The thing is that there may be text written over the objects, which results in that the objects are split into several parts. The text can be small and just inside some connected component or it may be many times larger than the components. I can generate a mask for the text based on its color. I want to ignore the text somehow, but I'm not quite sure how.

I see three possible ways forward: -Deal with this when first getting the connected components -Merge contours which are connected by the text mask -Get contours which include the text and then modify the contours afterwards

Any help with this would be much appreciated! Maybe there is even some clever OpenCV function for this? Thanks!

click to hide/show revision 2
Figured out how to add images

Detect contour with mask

Hi all,

I'm detecting circular objects in an image by first getting a binary map based on color deviation from the background and then getting the contours of the connected components (and then a bunch of other stuff). The thing is that there may be text written over the objects, which results in that the objects are split into several parts. The text can be small and just inside some connected component or it may be many times larger than the components. I can generate a mask for the text based on its color. I want to ignore the text somehow, but I'm not quite sure how.

image description

In this case the fitting for three connected components has failed due to overlapping text. In the leftmost case no fitting could be made (no black circles around object) since the "O" excludes a piece of the object. In the middle case there are many small incorrect circles fitted because the contour gets fragmented. In the right case the fitting is bad due to the overlapping text.

I see three possible ways forward: forward:

-Deal with this when first getting the connected components components

-Merge contours which are connected by the text mask mask

-Get contours which include the text and then modify the contours afterwards

Any help with this would be much appreciated! Maybe there is even some clever OpenCV function for this? Thanks!