簡體   English   中英

錯誤opencv錯誤斷言失敗(p [-1] <= 2)是什么意思,該如何處理?

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

我正在嘗試使用OpenCV庫將Mathlab代碼轉換為pluses。

在下面的行中:

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]的含義以及為什么它不應該大於2(但是我想這里有些東西又與層有關)。

sig_temp三通道Mat矩陣。

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)

據我據此了解: https : //github.com/opencv/opencv/pull/8718/files MatSize :: p是尺寸大小的數組。

p [-1]為您提供金額尺寸。 也許您的sig_temp矩陣是3維或更大的?

我的建議是使用定義sig_temp的重塑方法為

cv::Mat3b sig_temp;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM