Declare mat in opencv Java

How to create and assign a mat using java opencv? The C version starting from this page is

Mat C = (Mat_<double>(3,3) << 0,-1,5,0);

What is the equivalent in Java opencv? There seems to be a lack of documentation for Java OpenCV Existing content usually contains C code that does not work in Java

Solution

Yes Few or no documents exist amount to

Mat img = new Mat( 3,3,CvType.CV_64FC1 );
int row = 0,col = 0;
img.put(row,col,0 );

In the opencv Java doc (1) of matclass, see the overloaded put method

public int put(int row,int col,double... data )
public int put(int row,float[] data )
public int put(int row,int[] data )
public int put(int row,short[] data )
public int put(int row,byte[] data )

We can see that for data types other than double, the last parameter is array rather than variable parameter type Therefore, if we choose to create different types of mat, we will need to use the following array

int row = 0,col = 0;
int data[] = {  0,0 };
//allocate Mat before calling put
Mat img = new Mat( 3,CvType.CV_32S );
img.put( row,data );
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>