declare Mat in OpenCV java
17,044
Yes. The documentation is minimal or non existing. An equivalent would be
Mat img = new Mat( 3, 3, CvType.CV_64FC1 );
int row = 0, col = 0;
img.put(row ,col, 0, -1, 0, -1, 5, -1, 0, -1, 0 );
In opencv java doc(1) for Mat
class, see the overloaded put
method
public int put(int row, int col, double... data )
public int put(int row, int col, float[] data )
public int put(int row, int col, int[] data )
public int put(int row, int col, short[] data )
public int put(int row, int col, byte[] data )
We can see that for data types other than double
, the last parameter is an array and not variable argument type. So if choosing to create Mat
of different type, we will need to use arrays as below
int row = 0, col = 0;
int data[] = { 0, -1, 0, -1, 5, -1, 0, -1, 0 };
//allocate Mat before calling put
Mat img = new Mat( 3, 3, CvType.CV_32S );
img.put( row, col, data );
Related videos on Youtube
Author by
Kevin S. Miller
Updated on September 15, 2022Comments
-
Kevin S. Miller over 1 year
How can I create and assign a Mat with Java OpenCV? The C++ version from this page is
Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
What would be the equivalent in Java OpenCV? It seems that the documentation for Java OpenCV is lacking. What does exist often contains C++ code that doesn't work in Java.
-
pvd about 4 yearsHi @Kiran, would you mind help to take a look at this question? stackoverflow.com/questions/61226304/…
-
Kanad almost 4 yearsWhy are the row and col values zero? What does it mean?