Ask Your Question
0

Equivalent OpenCV Java Code to this C++ Code

asked 2016-04-27 21:55:21 -0600

Whats are equivalent opencv java code to the blocks below?

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

and

Mat temp;

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

floodFilled = temp;

Thanks

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-04-28 00:56:46 -0600

berak gravatar image

updated 2016-04-28 00:57:28 -0600

using java, this all gets a bit clumsy.

there are no "overloaded operators", and you cannot subtract a Mat from a Scalar, so you have to do like this:

    // build a Mat , filled with 255:
    Mat one = new Mat(floodFilled .size(), floodFilled.type(), new Scalar(255));
    // invert the floodFill Mat:
    Core.subtract(one, floodFilled, floodFilled);

the 2nd one is a simple submat():

    Mat floodFillRoi = floodFilled.submat(new Rect(1, 1, dilateGrad.cols-2, dilateGrad.rows-2)).

please bookmark a link to the docs , you'll need it ;)

edit flag offensive delete link more

Comments

Perfect. Thank you so much, berak.

marcelomg21 gravatar imagemarcelomg21 ( 2016-04-28 07:01:16 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-04-27 21:55:21 -0600

Seen: 250 times

Last updated: Apr 28 '16