Java Opencv Mat构造函数不匹配



我正在尝试创建一个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;
}

这是一个bug,还是?

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

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

最新更新