zakjma
zakjma

Reputation: 2110

Opencv - FloodFill doesn't change mask image

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.

Upvotes: 1

Views: 1509

Answers (1)

Steven Veltema
Steven Veltema

Reputation: 2150

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;

Upvotes: 1

Related Questions