OpenCV-FloodFill不会更改蒙版图像 [英] Opencv - FloodFill doesn't change mask image

查看:101
本文介绍了OpenCV-FloodFill不会更改蒙版图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的android应用程序上使用FloodFill算法.单击一个点以选择种子,然后运行Floodfill算法.我只想显示与种子颜色相同的选定区域.为此,我显示了遮罩垫对象.但是每次都是黑色的,它不会改变.我使用了FLOODFILL_FIXED_RANGEFLOODFILL_MASK_ONLY标志.

I try to use floodFill algorithm on my android application. I click a point to select seed.Then I run floodfill algorithm. I want to show only selected area same as seed color. To do this, I display mask mat object. But it is black everytime, it doens't change. I used FLOODFILL_FIXED_RANGE and FLOODFILL_MASK_ONLY flags.

我的代码在这里:

Imgproc.cvtColor(mRgba, temp, Imgproc.COLOR_RGBA2RGB);
        Imgproc.cvtColor(temp, temp, Imgproc.COLOR_RGB2GRAY);
        mMask = Mat.zeros(mMask.size(), CvType.CV_8UC1);
        Imgproc.floodFill(temp, mMask, fpts.get(fpts.size()-1), new Scalar(255, 255, 255),new Rect(new Point(0,0), new Point(5,5)),new Scalar(30), new Scalar(30), Imgproc.FLOODFILL_FIXED_RANGE);      
        Core.circle(temp, fpts.get(fpts.size()-1), 7, new Scalar(255, 255, 255), RADIUS);
        Mat temp3 = new Mat(temp.size(), mMask.type());
        temp3 = mMask.submat(new Rect( 2, 2, mMask.width()-2, mMask.height()-2)) ;

        Log.i(TAG, temp3.width() + "-" + temp3.height()+"**" + temp.width()+"-"+temp.height());
        // / Show me what you got from template matching
        Core.rectangle(temp, matchLoc, new Point(matchLoc.x + mTemp.cols(),
                matchLoc.y + mTemp.rows()), new Scalar(0, 255, 0));
        return temp3;

如果我返回temp,则可以显示更改后的输入图像.

If I return temp, I can show changed input image.

推荐答案

您需要在Imgproc.floodFill标志中设置掩码的新值.要将蒙版更改为白色(255):

You need to set the new value for the mask in the Imgproc.floodFill flags. To change the mask to white (255):

int flags = 4 + (255 << 8) + Imgproc.FLOODFILL_FIXED_RANGE;

这篇关于OpenCV-FloodFill不会更改蒙版图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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