2

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?

Svetlin Zarev
  • 14,713
  • 4
  • 53
  • 82

1 Answers1

2

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

James Barnett
  • 5,039
  • 3
  • 15
  • 18
  • But make sure to remember in which order you are filling up the values , i.e in RGB or BRG , as their is no exact format like you have in [Java Point Class](http://docs.oracle.com/javase/7/docs/api/java/awt/Point.html) – GiriB Sep 26 '15 at 12:04