开发者

Access element of float cv::Mat

I don't understand why I can't get this code to work:

cv::Mat M(2, 3, CV_32FC1);
cv::Point2f center(20, 20);
M = cv::getRotationMatrix2D(center, 20, 1.0);
float test;
test = M.at<float>(1, 0);
test = M.at<float>(0, 1);
test = M.at<float>(1, 1);

The code fails when accessing the elements with M.at. The following assertion comes up:

OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)si
ze.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigne开发者_C百科d)(size.p[1]*channel
s()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3
) - 1))*4) & 15) == elemSize1()) in unknown function, file C:\OpenCV2.2\include\
opencv2/core/mat.hpp, line 517


To quote Good Will Hunting, "It's not your fault!"

M has been overwritten with a CV_64C1 or a double rotation matrix and that's why M.at<float>(i,j) fails.

So, don't bother initializing M ; cv::getRotationMatrix will take care of it and return a CV_64F matrix which can (of course) be accessed with M.at<double>(i,j).


I don't know anything about the cv namespace, but I would put a breakpoint at the first call to M.at() and look at the members of M. One of these members is causing the error:

  • dims <= 2
  • data == 0
  • i0 < size.p[0]
  • i1*DataType<_Tp>::channels < size.p[1]*channels()
  • ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1() //sure hope it isn't this one
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜