JayTheKay
JayTheKay

Reputation: 1483

Mat subtraction with OpenCV in Java

I'm trying to convert some opencv code from C++ to Java, but I'm stuck at this code:

Mat matXyz; // some Mat
Mat result; // some other Mat
// ... set above mats to some values ...
result = Mat::ones(matXyz.size(), CV_32F) - result;

First, I don't really understand what the last line even does. Second, I don't know how to transfer this line to Java (OpenCV 2.4.6), as there are no overloaded operators like in C++, and I could not find any comparable method in the Java class (see OpenCV Javadoc).

What is the best way to transfer this into Java?

Upvotes: 7

Views: 8905

Answers (1)

ggovan
ggovan

Reputation: 1927

There are matrix operations in the org.opencv.core.Core class, including subtraction operators.

Mat endResult;
Core.subtract(Mat.ones(matXyz.size(),CvType.CV_32F),result,endResult);

The last line of your code creates a Matrix filled with ones, the same size as matXyz, where the data are floating point numbers. It is all described in the docs that you linked.

Upvotes: 10

Related Questions