OpenCV 3d point projection
OpenCV 3d point projection
我在纠正OpenCV程序以投影3d点时遇到问题。在使用OpenCV的projectPoints
功能时,我似乎遇到了这个问题。
这是我得到的错误:
OpenCV 错误:断言失败(mtype == type0 ||(CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 <<type0) & fixedDepthMask) != 0))在创建中,文件/home/daniel/Comp4102/opencv/modules/core/src/matrix.cpp,第 2375 行 在抛出"cv::异常"实例后终止调用 what():/home/daniel/Comp4102/opencv/modules/core/src/matrix.cpp:2375: 错误: (-215) mtype == type0 ||(CV_MAT_CN(mtype) == CV_MAT_CN(type0) && ((1 <<type0) & fixedDepthMask) != 0) in function create
这是我写的代码:
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <string>
std::vector<cv::Point3d> set3DPoints();
int main( int argc, char* argv[]) {
// Setting given variables.
double f = 500;
double sx = 1;
double sy = 1;
double ox = 320;
double oy = 240;
std::vector<cv::Point3d> objectPoints = set3DPoints();
cv::Mat Xw(1,3,cv::DataType<double>::type);
Xw.at<double>(0,0) = 150;
Xw.at<double>(0,1) = 200;
Xw.at<double>(0,2) = 350;
// Create the K matrix.
cv::Mat K(3,3,cv::DataType<double>::type);
K.at<double>(0,0) = -f/sx;
K.at<double>(1,0) = 0;
K.at<double>(2,0) = ox;
K.at<double>(0,1) = 0;
K.at<double>(1,1) = -f/sy;
K.at<double>(2,1) = oy;
K.at<double>(0,2) = 0;
K.at<double>(1,2) = 0;
K.at<double>(2,2) = 1;
// Creating the Rotation Matrix
cv::Mat R(3,3,cv::DataType<double>::type);
R.at<double>(0,0) = 1;
R.at<double>(1,0) = 0;
R.at<double>(2,0) = 0;
R.at<double>(0,1) = 0;
R.at<double>(1,1) = 1;
R.at<double>(2,1) = 0;
R.at<double>(0,2) = 0;
R.at<double>(1,2) = 0;
R.at<double>(2,2) = 1;
// Creating the Translation vector
cv::Mat T(3,1,cv::DataType<double>::type);
T.at<double>(0) = -70;
T.at<double>(1) = -95;
T.at<double>(2) = -120;
std::cout << "K: " << "n" << K << "n";
std::cout << "R: " << "n" << R << "n";
std::cout << "T: " << "n" << T << "n";
// Create zero distortion
cv::Mat distCoeffs(4,1,cv::DataType<double>::type);
distCoeffs.at<double>(0) = 0;
distCoeffs.at<double>(1) = 0;
distCoeffs.at<double>(2) = 0;
distCoeffs.at<double>(3) = 0;
// Creating Rodrigues rotation matrix
cv::Mat rvecR(3,1,cv::DataType<double>::type);
cv::Rodrigues(R,rvecR);
std::vector<cv::Point2f> projectedPoints;
cv::projectPoints(objectPoints, rvecR, T, K, distCoeffs, projectedPoints);
for(unsigned int i=0; i<projectedPoints.size(); i++){
std::cout << "Image point: " << objectPoints[i] << " Projected to " << projectedPoints[i] << "n";
}
return 0;
}
std::vector<cv::Point3d> set3DPoints() {
std::vector<cv::Point3d> points;
double x,y,z;
x=150;
y=200;
z=350;
points.push_back(cv::Point3d(x,y,z));
return points;
}
函数projectPoints
需要相同类型的参数objectPoints
和imagePoints
,而您将objectPoints
传递为Point3d
,imagePoints
传递为Point2f
。
错误告诉您这两种类型是不同的: double != float
.
只需将projectedPoints
声明为 Point2d
,以便它具有与 Point3d
相同的类型:
std::vector<cv::Point2d> projectedPoints;
相关文章:
- Qt5 部署"procedure entry point could not be located"
- 我想获取点的属性,它报告错误 C3867:"point::output_x":非标准语法;使用"&"创建指向成员的指针
- 如何从内存中分配GDI+ POINT类地址?
- 如何在OpenCV中存储部分轮廓点喜欢新矢量中的左侧,该类型为<vector<vector<Point>>
- 在每个向量<向量中查找最小/最大 x,y<Point>>
- "Entry Point Not Found" Azure 中的错误 LightGBM R 包
- 如何修复'The procedure entry point SDL_RWclose could not be located in the dynamic link library'
- 如何创建geometry_msgs :: point
- 为什么我会得到"floating point exception"
- Paraview:Live Point Cloud可视化插件
- Libavcodec "the procedure entry point for av_frame_alloc could not be located" Visual Studio 2017 C+
- 无法运行Qt C++发布版本。 'The procedure entry point could not be located'
- 没有用于初始化'point'的匹配构造函数
- CGAL 如何将 std::vector<Point> 点保存到 .xyz 文件中?
- 我如何理解"Point of Instantiation"的含义
- "[Error] pointer value used where a floating point value was expected" 如何解决此错误?
- CreatePolygonRgn and const POINT *
- Qt QGraphicsScene origin point
- 奇怪的"Entry Point Not Found"错误
- OpenCV 3d point projection