gpt4 book ai didi

image-processing - OpenCV - Floodfill 到新垫子上

转载 作者:太空宇宙 更新时间:2023-11-03 20:39:19 24 4
gpt4 key购买 nike

给定图像上的一个点,我想填充与该点相连的所有点 - 但要填充到新图像上。一种天真的方法是将原始图像填充为特殊的魔法颜色值。然后,访问每个像素,并将具有这个神奇颜色值的所有像素复制到新图像中。一定有更好的方法!

最佳答案

为什么不使用 cv::floodFill 的第二个变体?制作面具?

int floodFill(InputOutputArray image, InputOutputArray mask, Point seedPoint, Scalar newVal, Rect* rect=0, Scalar loDiff=Scalar(), Scalar upDiff=Scalar(), int flags=4 )


  • 原始图片
cv::Mat img = cv::imread("squares.png");

squares

  • 第一个变体
cv::floodFill(img, cv::Point(150,150), cv::Scalar(255.0, 255.0, 255.0));

img

这是img

  • 第二种变体
cv::Mat mask = cv::Mat::zeros(img.rows + 2, img.cols + 2, CV_8U);
cv::floodFill(img, mask, cv::Point(150,150), 255, 0, cv::Scalar(), cv::Scalar(),
4 + (255 << 8) + cv::FLOODFILL_MASK_ONLY);

mask

这是掩码img 不变


如果您选择这样做,请注意:

Since the mask is larger than the filled image, a pixel (x,y) in image corresponds to the pixel (x+1, y+1) in the mask.

关于image-processing - OpenCV - Floodfill 到新垫子上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12574937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com