错误opencv错误断言失败(p [-1]< = 2)是什么意思以及如何处理它?

时间:2017-10-22 15:22:56

标签: c++ matlab opencv image-processing

我试图使用OpenCV库将Mathlab代码转换为插件。

在下面一行:

resize (sig_temp, sig_temp, \
Size (sig_temp.size [0] / 2 + sig_temp.size [0]% 2, \
sig_temp.size [1] / 2 + sig_temp.size [1]% 2));

该程序出现错误:

opencv error assertion failed (p[-1] <= 2) in cv::Matsize:: operator ()

之前的错误(dims <= 2, top / bottom / right / left> = 0)非常明显,因为很明显尺寸不应超过两个,图像的边界应该是非负的。我立即不明白p [-1]意味着什么,为什么它不应该超过两个(但我想这里有些东西再次与层连接)。

sig_temp - 三通道 Mat 矩阵。

2 个答案:

答案 0 :(得分:0)

cv::Sizeint width, int height作为参数。 Mat::size的第0个元素是高度。

cv::Mat img = imread("image.jpg");

cout<<img.size()<<endl; // This line prints [columns x rows]
cout<<img.size[0]<<endl; // This line prints the rows
cout<<img.size[1]<<endl; // This line prints the columns

所以在这一行:

Size (sig_temp.size [0] / 2 + sig_temp.size [0]% 2, \
sig_temp.size [1] / 2 + sig_temp.size [1]% 2)

您将int height, int width作为cv::Size的参数,将int width, int height作为参数。

您应该使用行和列来避免混淆。

Size (sig_temp.cols / 2 + sig_temp.cols% 2, \
    sig_temp.rows / 2 + sig_temp.rows% 2)

答案 1 :(得分:0)

据我所知,从中可以看出: https://github.com/opencv/opencv/pull/8718/files MatSize :: p是尺寸大小的数组。

p [-1]为您提供金额维度。也许你的sig_temp矩阵是3维或更多?

我的建议是使用定义sig_temp的reshape方法作为

cv::Mat3b sig_temp;