Ask Your Question

Bazooka's profile - activity

2019-03-14 00:27:41 -0500 received badge  Popular Question (source)
2017-01-16 06:19:23 -0500 received badge  Self-Learner (source)
2017-01-16 05:19:20 -0500 received badge  Scholar (source)
2017-01-16 05:18:48 -0500 answered a question How to floodfill an image with java api

I just realized that this line

floodFilled(Rect(1, 1, src.cols - 2, src.rows - 2)).copyTo(temp);

It's justing defining a submatrix with the ROI(region of intresting), so I did this and got it working well:

private static Mat floodFill(Mat img)
{
    Mat floodfilled = Mat.zeros(img.rows() + 2, img.cols() + 2, CvType.CV_8U);
    Imgproc.floodFill(img, floodfilled, new Point(0, 0), new Scalar(255), new OpenCVForUnity.Rect(), new Scalar(0), new Scalar(0), 4 + (255 << 8) + Imgproc.FLOODFILL_MASK_ONLY);

    Core.subtract(floodfilled, Scalar.all(0), floodfilled);

    Rect roi = new Rect(1, 1, img.cols() - 2, img.rows() - 2);
    Mat temp = new Mat();

    floodfilled.submat(roi).copyTo(temp);

    img = temp;

    //Core.bitwise_not(img, img);

    return img;
}
2017-01-13 10:48:13 -0500 commented answer How to floodfill an image with java api

And the 2nd didn't work cause floodFilled is a Mat object, I can't call a constructor this way, or I got you wrong. The error is "Method name expected" for the second line.

2017-01-13 10:33:54 -0500 commented answer How to floodfill an image with java api

Did you mean Core.subtract right ?

2017-01-13 10:15:28 -0500 asked a question How to floodfill an image with java api

I got it working fine when I did it with C++, it was like:

 Mat floodFilled = cv::Mat::zeros(src.rows + 2, src.cols + 2, CV_8U);

floodFill(src, floodFilled, cv::Point(0, 0), 0, 0, cv::Scalar(), cv::Scalar(), 4 + (255 << 8) + cv::FLOODFILL_MASK_ONLY);
floodFilled = cv::Scalar::all(255) - floodFilled;

Mat temp;
floodFilled(Rect(1, 1, src.cols - 2, src.rows - 2)).copyTo(temp);
floodFilled = temp;
imshow("5. Floodfill", floodFilled);

But I can't reproduce this in java because some features does not exist there, like these lines:

floodFilled = cv::Scalar::all(255) - floodFilled;

I can't subtract a matrix from a scalar this way.

floodFilled(Rect(1, 1, src.cols - 2, src.rows - 2)).copyTo(temp);

this constructor does not exist either.

The output image was exactly the same as the input one.

So, I want to be able to do the same thing that I did in C++, with java instead. Thanks in advance.