[英]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.使用 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) < (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:\OpenCV2.2\include\
opencv2/core/mat.hpp, line 517
To quote Good Will Hunting, "It's not your fault!"引用Good Will Hunting的话, “这不是你的错!”
M
has been overwritten with a CV_64C1
or a double
rotation matrix and that's why M.at<float>(i,j)
fails. M
已被CV_64C1
或double
旋转矩阵覆盖,这就是M.at<float>(i,j)
失败的原因。
So, don't bother initializing M
;所以,不要费心初始化
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)
. cv::getRotationMatrix
将处理它并返回一个CV_64F
矩阵,(当然)可以使用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:我对 cv 命名空间一无所知,但我会在第一次调用 M.at() 时放置一个断点并查看 M 的成员。其中一个成员导致错误:
//sure hope it isn't this one
//sure hope it isn't this one
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.