在 OpenCV java 中声明 Mat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27338864/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
declare Mat in OpenCV java
提问by Kevin S. Miller
How can I create and assign a Mat with Java OpenCV? The C++ version from this pageis
如何使用 Java OpenCV 创建和分配 Mat?此页面的 C++ 版本是
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.
Java OpenCV 中的等价物是什么?似乎缺少 Java OpenCV 的文档。存在的内容通常包含在 Java 中不起作用的 C++ 代码。
回答by Kiran
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
在 opencv java doc( 1) for Mat
class 中,查看重载put
方法
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
我们可以看到,对于除 之外的数据类型double
,最后一个参数是一个数组,而不是可变参数类型。所以如果选择创建Mat
不同的类型,我们将需要使用如下数组
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 );