【问题标题】:Java Opencv Mat constructor mismatchJava Opencv Mat 构造函数不匹配
【发布时间】:2016-11-14 11:42:41
【问题描述】:

我正在尝试按如下方式创建一个 Mat 对象:

// ROI by creating mask for the trapezoid
Mat mask = Mat(frame.rows(), frame.cols(), CvType.CV_8UC1, new Scalar(0));

但是我得到以下编译时错误:

The method Mat(int, int, int, Scalar) is undefined for the type 

而在Mat.class 文件中,我肯定可以看到以下函数签名:

//
// C++: Mat::Mat(int rows, int cols, int type, Scalar s)
//

// javadoc: Mat::Mat(rows, cols, type, s)
public Mat(int rows, int cols, int type, Scalar s)
{

    nativeObj = n_Mat(rows, cols, type, s.val[0], s.val[1], s.val[2], s.val[3]);

    return;
}

这是一个错误,还是?

【问题讨论】:

  • 不应该是Mat mask = new Mat(...)吗?
  • 你是对的,我很愚蠢,我正在将代码从 C++ 转换为 Java,因此出现了错误。如果你写它,我会接受它作为答案。谢谢。

标签: java c++ opencv


【解决方案1】:

签名正确。 在 Java 中,您需要使用 new 关键字来创建新对象:

Mat mask = new Mat(frame.rows(), frame.cols(), CvType.CV_8UC1, new Scalar(0));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 2011-12-28
    • 1970-01-01
    • 1970-01-01
    • 2022-11-29
    • 2017-07-18
    • 2020-01-14
    相关资源
    最近更新 更多