Opencv - FloodFill doesn't change mask image

让人想犯罪 __ 提交于 2019-12-11 11:47:53

问题


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.

My code is here :

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;

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


回答1:


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;


来源:https://stackoverflow.com/questions/29275407/opencv-floodfill-doesnt-change-mask-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!