本文介绍了使用OpenCV洪水填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想使用洪水填充,但失败了,而且我从未使用过,所以我认为自己做错了.

I just wanna use the flood fill but it fails and I never used it so i think I am doing something wrong.

Mat flooded=new Mat();
Point flood=new Point(1,1);
// floodedmat = Mat.zeros(myMat2.size(), CvType.CV_8UC1);
Imgproc.floodFill(myMat2, flooded, flood, new Scalar(255, 255, 255));
Utils.matToBitmap(flooded, copy);

填充洪水后,我打算将其返回到位图以显示它,以便看到更改.

After the flood fill I intend to return it to bitmap to display it so I will see changes.

推荐答案

您应使用带有其他参数的重载FloodFill方法:

You should use the overloaded floodFill method which takes additional parameters:

Imgproc.floodFill(myMat2, flooded, flood, new Scalar(255, 255, 255), new Rect(), lowerDiff, upperDiff, 4);

新的Rect()对象是一个边界矩形,其中将包含您的泛洪; lowerDiffupperDiff应该初始化为具有与原始像素值不同的值的标量(即:如果它是具有不同颜色值的RGB图像,则可以说在您的种子点(泛洪)处有一个明亮的黄色像素,周围的像素会稍微变亮或变亮,而黄色像素会被白色矩形填充).您想使用3个值来初始化它们,即:

The new Rect() object is a bounding rectangle which will contain your floodfill; lowerDiff and upperDiff should be initialized scalars with a difference value to your original pixel value (ie: if it's a RGB image with difference in color values, lets say at your seed point (flood) there is a bright yellow pixel and it is surrounded by a slightly less bright or slightly more bright yellow pixels, it will fill them with white color rectangles). You want to initialize them with 3 values, ie:

Scalar lowerDiff = new Scalar(10, 10, 10);

最后一个整数参数是FloodFill实际上应该考虑多少个相邻像素,默认为4,另一个为8. (4个将拍摄北部,东部,西部和南部像素,而8个将拍摄北部,东北,东部,东南等像素.

And the final integer argument is how many neighbouring pixels should the floodFill actually take into consideration, 4 is default, 8 is another option. (4 will take northern, eastern, western, and southern pixels, while 8 will take north, north-eastern, eastern, south-eastern, etc.. pixels).

这篇关于使用OpenCV洪水填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 08:48