org.opencv.imgproc.Imgproc.floodFill()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(3.0k)|赞(0)|评价(0)|浏览(210)

本文整理了Java中org.opencv.imgproc.Imgproc.floodFill()方法的一些代码示例,展示了Imgproc.floodFill()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Imgproc.floodFill()方法的具体详情如下:
包路径:org.opencv.imgproc.Imgproc
类名称:Imgproc
方法名:floodFill

Imgproc.floodFill介绍

[英]Fills a connected component with the given color.

The functions floodFill fill a connected component starting from the seed point with the specified color. The connectivity is determined by the color/brightness closeness of the neighbor pixels. The pixel at (x,y) is considered to belong to the repainted domain if:

  • src(x',y')- loDiff

in case of a grayscale image and floating range

  • src(seedPoint.x, seedPoint.y)- loDiff

in case of a grayscale image and fixed range

  • src(x',y')_r- loDiff _r

src(x',y')_g- loDiff _g

and

src(x',y')_b- loDiff _b

in case of a color image and floating range

  • src(seedPoint.x, seedPoint.y)_r- loDiff _r

src(seedPoint.x, seedPoint.y)_g- loDiff _g

and

src(seedPoint.x, seedPoint.y)_b- loDiff _b

in case of a color image and fixed range

where src(x',y') is the value of one of pixel neighbors that is already known to belong to the component. That is, to be added to the connected component, a color/brightness of the pixel should be close enough to:

  • Color/brightness of one of its neighbors that already belong to the connected component in case of a floating range.
  • Color/brightness of the seed point in case of a fixed range.

Use these functions to either mark a connected component with the specified color in-place, or build a mask and then extract the contour, or copy the region to another image, and so on.

Note:

  • An example using the FloodFill technique can be found at opencv_source_code/samples/cpp/ffilldemo.cpp
  • (Python) An example using the FloodFill technique can be found at opencv_source_code/samples/python2/floodfill.cpp
    [中]使用给定的颜色填充连接的零部件。
    函数floodFill使用指定的颜色从种子点开始填充连接的组件。连通性由相邻像素的颜色/亮度接近度决定。如果满足以下条件,则认为*(x,y)*处的像素属于重绘域:
    *src(x',y')-loDiff
    如果是灰度图像和浮动范围
    *src(seedPoint.x,seedPoint.y)-loDiff
    对于灰度图像和固定范围
    *src(x',y')\u r-loDiff\r
    src(x',y')(g-loDiff)

    src(x',y')(b-loDiff)
    如果是彩色图像和浮动范围
    *src(seedPoint.x,seedPoint.y)\r-loDiff\r
    src(seedPoint.x,seedPoint.y)\g-loDiff\g

    src(seedPoint.x,seedPoint.y)\u b-loDiff\u b
    对于彩色图像和固定范围
    其中,*src(x',y')*是已知属于组件的像素邻域之一的值。也就是说,要添加到连接的组件,像素的颜色/亮度应足够接近:
    *在浮动范围内,已属于连接组件的相邻组件之一的颜色/亮度。
    *在固定范围内,种子点的颜色/亮度。
    使用这些函数可以使用指定的颜色标记连接的零部件,或者构建遮罩,然后提取轮廓,或者将区域复制到另一个图像,等等。
    注:
    *在opencv_source_code/samples/cpp/ffilldemo中可以找到使用泛洪填充技术的示例。cpp
    *(Python)在opencv_source_code/samples/python2/FloodFill中可以找到使用FloodFill技术的示例。cpp

代码示例

代码示例来源:origin: openpnp/openpnp

public FluentCv floodFill(Point seedPoint, Color color, String... tag) {
  Mat mask = new Mat();
  Imgproc.floodFill(mat, mask, seedPoint, colorToScalar(color));
  return store(mat, tag);
}

代码示例来源:origin: JavaOpenCVBook/code

int area = 0;
if(masked){
  area = Imgproc.floodFill(image, mask, seedPoint, newVal, rect, lowerDifference,
      upperDifference, flags);
  area = Imgproc.floodFill(image, new Mat(), seedPoint, newVal, rect, lowerDifference,
      upperDifference, flags);

代码示例来源:origin: JavaOpenCVBook/code

int area = 0;
if(masked){
  area = Imgproc.floodFill(image, mask, seedPoint, newVal, rect, lowerDifference,
      upperDifference, flags);
  area = Imgproc.floodFill(image, new Mat(), seedPoint, newVal, rect, lowerDifference,
      upperDifference, flags);

相关文章

微信公众号

最新文章

更多

Imgproc类方法