OpenCV FloodFill具有多个种子 [英] OpenCV FloodFill with multiple seeds

查看:109
本文介绍了OpenCV FloodFill具有多个种子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有适用于python/openCV的FloodFill函数,该函数获取种子列表并开始更改其邻居的颜色?我知道simplecv是像这样的函数 SimpleCV FloodFill . OpenCV表示,当使用掩码时,它具有两个FloodFill函数,而另一个不使用,

Is there a floodFill function for python/openCV that takes a list of seeds and starts changing the color of its neighbours? I know that simplecv as a function like that SimpleCV floodFill. OpenCV says it has two floodFill functions when that uses a mask and another one that doesn't, documentation, I'm not being able to use the opencv floodfill function without a mask and with a list of seeds. Any help?

这是我到目前为止想要做的:

This is what I'm trying to do so far:

A=array([[0,1,1,0],[0,0,0,0],[1,1,1,1],[1,1,1,1]],np.uint8)
mask = np.ones((A.shape[0]+2,A.shape[0]+2),np.uint8)
mask[1:-1,1:-1] = np.zeros((A.shape))
cv.floodFill(A, mask, (3,0), 0,0,0,  flags=4|cv.FLOODFILL_MASK_ONLY)
print mask

回面罩:

[[1 1 1 1 1 1]
 [1 1 0 0 1 1]
 [1 1 1 1 1 1]
 [1 0 0 0 0 1]
 [1 0 0 0 0 1]
 [1 1 1 1 1 1]]

预期的遮罩:

[[1 1 1 1 1 1]
 [1 0 0 0 0 1]
 [1 0 0 0 0 1]
 [1 1 1 1 1 1]
 [1 1 1 1 1 1]
 [1 1 1 1 1 1]]

原始图片:

[[0 1 1 0]
 [0 0 0 0]
 [1 1 1 1]
 [1 1 1 1]]

推荐答案

如果仔细阅读文档,这就是遮罩的目的之一.您可以每次使用不同的种子多次调用该函数(第二版),并且最后,遮罩将包含已被填充的区域.如果新种子属于已经充满的区域,则您的函数调用将立即返回.

If you look closely at the documentation, that's one of the purpose of mask. You can call multiple times the function (2nd version) every time with a different seed, and at the end mask will contain the area that has been floodfilled. If a new seed belongs to an area already floodfilled, your function call will return immediately.

使用FLOODFILL_MASK_ONLY标志,然后使用此蒙版在输入图像的末尾加上

Use the FLOODFILL_MASK_ONLY flag, and then use this mask to paint your input image with the desidered filling color at the end with a setTo() (You'll have to use a subimage of Mask! Removing first and last row and column). Note that your floodfill might produce different results depending on the order you process your seed points if you set loDiff or upDiff to something different than the default value zero.

还请参见.

这篇关于OpenCV FloodFill具有多个种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆