问题描述
如何使用Java OpenCV创建和分配Mat? 此页面的C ++版本是
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);
Java OpenCV中的等效内容是什么?似乎缺少Java OpenCV的文档.确实存在的内容通常包含在Java中不起作用的C ++代码.
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.
推荐答案
是.该文档很少或不存在.等效为
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 );
在Opencv Java文档中( 1 )用于Mat
类,请参见重载的put
方法
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 )
我们可以看到,对于double
以外的数据类型,最后一个参数是数组,而不是变量参数类型.因此,如果选择创建不同类型的Mat
,我们将需要使用以下数组
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 );
这篇关于在OpenCV Java中声明Mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!