简体   繁体   中英

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.

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

sig_temp - three-channel Mat matrix .

cv::Size takes int width, int height as parameters. The 0th element of Mat::size is height.

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.

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.

p[-1] gives you amounts dimensions. maybe your sig_temp matrix is 3 dimensional or more?

my suggestion is either use its reshape method of define sig_temp as

cv::Mat3b sig_temp;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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