简体   繁体   English

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

[英]What does the error opencv error assertion failed (p [-1] <= 2) mean and how to deal with it?

I'm trying to translate the Mathlab code into pluses, using the OpenCV library. 我正在尝试使用OpenCV库将Mathlab代码转换为pluses。

On the line below: 在下面的行中:

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));

The program falls with an error: 该程序出错:

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

The previous errors (dims <= 2, top / bottom / right / left> = 0) were pretty obvious, because of them it was clear that the dimensions should not be more than two, the boundaries of the image should be non-negative. 先前的错误(dims <= 2, top / bottom / right / left> = 0)非常明显,因为这些错误很明显,尺寸不应超过两个,图像的边界应为非负数。 Immediately I do not understand what p [-1] means and why it should not be more than two (but I guess that here something is again connected with layers). 立即我不明白p [-1]的含义以及为什么它不应该大于2(但是我想这里有些东西又与层有关)。

sig_temp - three-channel Mat matrix . sig_temp三通道Mat矩阵。

cv::Size takes int width, int height as parameters. cv::Sizeint width, int height为参数。 The 0th element of Mat::size is 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

So in this line: 所以在这一行:

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

You're giving int height, int width as parameters to cv::Size which takes int width, int height as params. 您正在将int height, int width作为参数提供给cv::Size ,该参数将int width, int height作为参数。

You should use rows and cols to avoid confusion. 您应该使用行和列来避免混淆。

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

as far as i can understand from this: https://github.com/opencv/opencv/pull/8718/files MatSize::p is the array of dimension sizes. 据我据此了解: https : //github.com/opencv/opencv/pull/8718/files MatSize :: p是尺寸大小的数组。

p[-1] gives you amounts dimensions. p [-1]为您提供金额尺寸。 maybe your sig_temp matrix is 3 dimensional or more? 也许您的sig_temp矩阵是3维或更大的?

my suggestion is either use its reshape method of define sig_temp as 我的建议是使用定义sig_temp的重塑方法为

cv::Mat3b sig_temp;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM