http://pastebin.com/5ZeMvm2C is my header file in my project.
There are skeleton.at(yaxis,xaxis+1) at line 249. When i type this code in my project i got this error:
**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.
Mat::at()
method has been implemented as a template, you must know the type of image before you used the function.check the channels of the image. for single channel image(8UC1), you should manipulate the image pixels as in:
for three channel color image(8UC3), you should use the function as in:
if the channel is no problem, you should check the arguments of the
at(i, j)
, i present the row, j present the col. in other word, i equal to Point.y, j equal to Point.x.As the error message says, you have an OpenCV runtime assertion that is failed.
As you wrote in your question, the failed assertion is inside the
Mat::at
function.You have to find in your code the call (or the calls) to
Mat::at
that give you the error.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:template<typename T> T& Mat::at(int i, int j)
,i
is supposed to be between0
and the number of rows minus one,j
is supposed to be between0
and the number of column minus one. If you have an image with 100 rows and you ask for an element at row 101 the assertion will fail. 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 isfalse
: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())
The above
bool
s are meaningful inside the scope ofMat
class.Furthermore please note that help says that:
and so in your Release configuration you will not have the failed assertion but probably a crash somewhere.
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 previousbool
s isfalse
.