Frage

I've written an image processing routine with OpenCV in C++.

Right now I am converting my code into Java, because I have more Java skills than C++.

I am using the Scalar Datatype out of the org.opencv.core.Scalar Library.

In C++ I was able to extract single Scalar values just like this

Scalar scalar = Scalar(1.0,2.0,3.0);
double value1 = scalar[0];

If i do this in Java I get the Error "array required, but scalar found".

How can I get single Values out of a Scalar in Java?

War es hilfreich?

Lösung

Since Scalars val field is public, you can just do

double value1 = scalar.val[0];

Although it's a bit unusual to access the fields directly, they provide no get method in the API, so this is the correct way to do it.

Scalar

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top