Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mat subtraction with OpenCV in Java

Tags:

java

c++

opencv

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?

like image 284
JayTheKay Avatar asked Sep 24 '13 16:09

JayTheKay


1 Answers

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.

like image 90
ggovan Avatar answered Sep 22 '22 06:09

ggovan