[英]Assertion failed error using opencv
I'm trying to run the example in the apriltags library, and I keep getting this error: 我正在尝试在apriltags库中运行示例,并且不断收到此错误:
OpenCV Error: Assertion failed (mtype == type0 || (CV_MAT_CN(mtype) == 1 && ((1 << type0) & fixedDepthMask) != 0)) in create, file /Users/Vijin/PersInq/opencv-3.2.0/modules/core/src/matrix.cpp, line 2559
I narrowed it down to a function call 我将其范围缩小到一个函数调用
detection.getRelativeTranslationRotation(m_tagSize, m_fx, m_fy, m_px, m_py,
translation, rotation);
I'm not an expert in opencv, so I'd appreciate some help with this. 我不是opencv的专家,所以我希望对此有所帮助。 The exception is thrown the moment a marker is detected. 一旦检测到标记,就会引发异常。 Otherwise, it runs fine. 否则,它将运行正常。 Here's the whole function: 这是整个功能:
void print_detection(AprilTags::TagDetection& detection) const {
cout << " Id: " << detection.id
<< " (Hamming: " << detection.hammingDistance << ")";
// recovering the relative pose of a tag:
// NOTE: for this to be accurate, it is necessary to use the
// actual camera parameters here as well as the actual tag size
// (m_fx, m_fy, m_px, m_py, m_tagSize)
Eigen::Vector3d translation;
Eigen::Matrix3d rotation;
try{
detection.getRelativeTranslationRotation(m_tagSize, m_fx, m_fy, m_px, m_py,
translation, rotation);
}
catch (const std::exception& e)
{
cout<<"print_detection failing";
}
Eigen::Matrix3d F;
F <<
1, 0, 0,
0, -1, 0,
0, 0, 1;
Eigen::Matrix3d fixed_rot = F*rotation;
double yaw, pitch, roll;
wRo_to_euler(fixed_rot, yaw, pitch, roll);
cout << " distance=" << translation.norm()
<< "m, x=" << translation(0)
<< ", y=" << translation(1)
<< ", z=" << translation(2)
<< ", yaw=" << yaw
<< ", pitch=" << pitch
<< ", roll=" << roll
<< endl;
// Also note that for SLAM/multi-view application it is better to
// use reprojection error of corner points, because the noise in
// this relative pose is very non-Gaussian; see iSAM source code
// for suitable factors.
} }
This issue persists with the newer versions of OpenCV. 较新版本的OpenCV仍然存在此问题。 It can be easily fixed by changing line 95 of src/TagDetection.cc
from cv::Matx33f cameraMatrix(
to cv::Matx33d cameraMatrix(
. 可以通过将src/TagDetection.cc
第95行从cv::Matx33f cameraMatrix(
更改为cv::Matx33d cameraMatrix(
。
Note, this is simply converting from float
to double
. 注意,这只是从float
转换为double
。 Alternatively, you can use this library ( https://github.com/PrieureDeSion/apriltags-cpp ), which I have made changes to and tested with Ubuntu 16 and OpenCV. 或者,您可以使用此库( https://github.com/PrieureDeSion/apriltags-cpp ),我已对它进行了更改并在Ubuntu 16和OpenCV中进行了测试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.