gpt4 book ai didi

java - FloodFill 算法填充超出指定边界

转载 作者:太空宇宙 更新时间:2023-11-03 22:55:31 28 4
gpt4 key购买 nike

我想填充下面张贴的图像的某个区域“左侧的矩形”。为了填充该区域,我在该矩形内指定了一个点以了解像素值,如下所示:

    Log.D(TAG, "", "PixVal: "+gsMat.get(100, 240)[0]);//at that position the pixVal is 91 up ok
Log.D(TAG, "", "PixVal: "+gsMat.get(250, 60)[0]);//at that position the pixVal is 217 l ??peoblem
Log.D(TAG, "", "PixVal: "+gsMat.get(330, 310)[0]);//at that position the pixVal is 123 down ok
Log.D(TAG, "", "PixVal: "+gsMat.get(330, 580)[0]);//at that position the pixVal is 84 r ok

而且我确定点(x=60,y=250)位于左侧的矩形内。我写了下面的代码来填充那个区域。但我得到了下面张贴的图片

"Mat subbed = gsRawMat.submat(r)" shows the whole orignal image as if the the whole pixel values in the image lays within the range of 216 to 218?

"ImageUtils.showMat(subbed, "subbed");" shows a white image as if the the whole pixel values in the image lays within the range of 216 to 218, hence, the whole area painted in white (255)?

请告诉我为什么会发生这种行为

代码:

    Mat m = new Mat();
Rect r = new Rect();
Imgproc.floodFill(gsMat,
m,
new Point(60, 250),
new Scalar(255),//to fill the designated area with color(255)
r,//the rect that will encompass the designated area
new Scalar(216),//lower bound
new Scalar(218),//upper bound
Imgproc.FLOODFILL_FIXED_RANGE);

Mat subbed = gsRawMat.submat(r);// to extract the rectangle contains the flooded area from the main image
ImageUtils.showMat(gsMat, "gsMat");//to show the gsmat
ImageUtils.showMat(subbed, "subbed");//to show the subbed area from the gsMat

结果 gsMat: enter image description here

结果底垫: enter image description here

最佳答案

这个函数我没有用过,但是根据(C++)文档,参数不是“下界”和“上界”,而是“下差”和“上差”。它们的亮度/颜色值是相对于种子点x=60,y=250的。我还没来得及想清楚,但会不会是这个原因呢?

http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#floodfill

关于java - FloodFill 算法填充超出指定边界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31366631/

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