python 图像填充颜色_Opencv:在轮廓图像中填充颜色

你应该把图像二值化。findContours只有在图像中只有黑白两种颜色时才能正常工作。在

所以你应该看看图像中的每个像素和阈值。如果低于某个值,则将其设为黑色,反之则将其设为白色。对我来说,提供的图像看起来也有一些灰色像素。在

你还应该知道,找到轮廓'破坏'提供的图像。它不会自己创建副本。所以如果你想保留原件,你应该交一份复印件。在

找到轮廓后,您可以使用原始图像上的信息并更改找到区域中像素的颜色值。在

编辑:

好吧,在我读了你的更新后,我推荐以下几点:

把有点蓝的背景变成黑色。

为此,您需要检查每个像素并查看颜色值。在

如果它有足够的蓝色,就把它变成黑色。

其他的都是你做的白色。在

之后你的背景应该是黑色的,你的数字应该是白色的。你现在可以做findContours,或者如果你只想让数字变成黑色而背景是白色:反转图像或者在二值化过程中交换黑白。在Important:

What you did with your image is actually not binarize it. You took the

color out. Binarize means only TWO colors. A pixel will EITHER be

black OR white. Not gray.

Your threshold is actually not thresholding because the value you took(255) is the maximum(because that is the highest number you can have with 8 bit). Thresholding works differently: for a binary threshold you have a value everything that is below or equal will be one color, everything that is above will be another. For 255 the whole image should turn to one color....

With thresholds you usualy play around a bit until they fit your needs

你可能感兴趣的:(python,图像填充颜色)