你应该把图像二值化。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

GitHub 加速计划 / opencv31 / opencv
238
21
下载
OpenCV: 开源计算机视觉库
最近提交(Master分支:4 个月前 )
74addff3 docs: fix spelling errors in code and comments 14 小时前
4cfd9689 Fix UB in cv::error when breakOnError set to true 17 小时前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐