简体   繁体   English

OpenCV错误:断言失败,mat.cpp行537

[英]OpenCV Error: Assertion failed, mat.cpp line 537

http://pastebin.com/5ZeMvm2C is my header file in my project. http://pastebin.com/5ZeMvm2C是我的项目中的头文件。

There are skeleton.at(yaxis,xaxis+1) at line 249. When i type this code in my project i got this error: 在第249行有skeleton.at(yaxis,xaxis + 1)。当我在项目中键入此代码时,出现此错误:

**OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si
ze.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channel
s()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3
) - 1))*4) & 15) == elemSize1()) in unknown function, file c:\opencv\build\inclu
de\opencv2\core\mat.hpp, line 537**

// mat.cpp line 537 is:
    template<typename _Tp> inline _Tp& Mat::at(int i0, int i1)
        {
            CV_DbgAssert( dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] &&
                (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) &&
                CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1());
            return ((_Tp*)(data + step.p[0]*i0))[i1];
        }

What's wrong? 怎么了?

http://pastebin.com/gqJ5RpBU is also my .cpp file. http://pastebin.com/gqJ5RpBU也是我的.cpp文件。

As the error message says, you have an OpenCV runtime assertion that is failed. 如错误消息所述,您有一个失败的OpenCV运行时断言。

As you wrote in your question, the failed assertion is inside the Mat::at function. 正如您在问题中所写的那样,失败的断言位于Mat::at函数内部。

You have to find in your code the call (or the calls) to Mat::at that give you the error. 您必须在代码中找到对Mat::at的调用(或多个调用) Mat::at这会给您带来错误。

As you can see at the OpenCV help page Mat::at is a template function with one, two or three arguments, the failure in the assertion can have various causes: 如您在OpenCV帮助页面上所见, Mat::at是带有一个,两个或三个参数的模板函数,断言失败可能有多种原因:

  1. you are using the wrong template parameter (see for example Using Mat::at(i,j) in opencv for a 2-D Mat object ) 您使用了错误的模板参数(例如,对于2D Mat对象,请参见在opencv中使用Mat :: at(i,j)
  2. the arguments are wrong, for example in a call to template<typename T> T& Mat::at(int i, int j) , i is supposed to be between 0 and the number of rows minus one, j is supposed to be between 0 and the number of column minus one. 参数是错误的,例如在对template<typename T> T& Mat::at(int i, int j)的调用中, i应该在0到行数减一之间,而j应该在之间0 ,列数减一。 If you have an image with 100 rows and you ask for an element at row 101 the assertion will fail. 如果您有一个包含100行的图像,并且在第101行请求一个元素,则断言将失败。 Off-by-one errors are common in this case. 在这种情况下,经常出现一对一的错误

To be more specific, the assertion failed because at least one of the following bool s is false : 更具体地说,断言失败,因为以下bool至少之一为false

  1. dims <= 2
  2. data
  3. (unsigned)i0 < (unsigned)size.p[0]
  4. (unsigned)(i1 * DataType<_Tp>::channels) < (unsigned)(size.p[1] * channels())
  5. CV_ELEM_SIZE1(DataType<_Tp>::depth) == elemSize1())

The above bool s are meaningful inside the scope of Mat class. 上面的boolMat类的范围内是有意义的。

Furthermore please note that help says that: 此外,请注意帮助说明:

For the sake of higher performance, the index range checks are only performed in the Debug configuration 为了提高性能,仅在Debug配置中执行索引范围检查

and so in your Release configuration you will not have the failed assertion but probably a crash somewhere. 因此,在您的Release配置中,您不会有失败的断言,而可能是某处崩溃。

From the source you linked, it seems to me that you are on Windows, if that is true and if you have Visual Studio, I suggest you to build OpenCV from the source code, to put a breakpoint inside Mat::at and then to debug your code in order to see what of the previous bool s is false . 从链接的源代码看,我看来您在Windows上,如果是这样,并且如果您具有Visual Studio,则建议您从源代码构建OpenCV,在Mat::at内放置一个断点,然后转到调试您的代码,以查看先前的bool是什么false

Mat::at() method has been implemented as a template, you must know the type of image before you used the function. Mat::at()方法已作为模板实现,使用该函数之前必须了解图像的类型。

check the channels of the image. 检查图像的通道。 for single channel image(8UC1), you should manipulate the image pixels as in: 对于单通道图像(8UC1),应按以下方式操作图像像素:

image.at<uchar>(row, col) = 255; 

for three channel color image(8UC3), you should use the function as in: 对于三通道彩色图像(8UC3),应使用以下功能:

image.at<cv::Vec3b>(row, col)[channel] = 255;

if the channel is no problem, you should check the arguments of the at(i, j) , i present the row, j present the col. 如果通道没有问题,则应检查at(i, j) ,我显示该行,j显示该列。 in other word, i equal to Point.y, j equal to Point.x . 换句话说,我等于Point.y,j等于Point.x

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

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