2
从图像点计算x,y坐标(3D)
我有一项任务是在3D坐标系中定位对象。由于我必须获得几乎精确的X和Y坐标,因此我决定跟踪一个具有已知Z坐标的颜色标记,该颜色标记将放置在移动对象的顶部,如该图中的橙色球: 首先,我已经完成了相机校准以获取固有参数,然后使用cv :: solvePnP来获取旋转和平移矢量,如以下代码所示: std::vector<cv::Point2f> imagePoints; std::vector<cv::Point3f> objectPoints; //img points are green dots in the picture imagePoints.push_back(cv::Point2f(271.,109.)); imagePoints.push_back(cv::Point2f(65.,208.)); imagePoints.push_back(cv::Point2f(334.,459.)); imagePoints.push_back(cv::Point2f(600.,225.)); //object points are measured in millimeters because calibration is done in mm also objectPoints.push_back(cv::Point3f(0., 0., 0.)); objectPoints.push_back(cv::Point3f(-511.,2181.,0.)); objectPoints.push_back(cv::Point3f(-3574.,2354.,0.)); objectPoints.push_back(cv::Point3f(-3400.,0.,0.)); cv::Mat rvec(1,3,cv::DataType<double>::type); cv::Mat tvec(1,3,cv::DataType<double>::type); cv::Mat rotationMatrix(3,3,cv::DataType<double>::type); cv::solvePnP(objectPoints, imagePoints, cameraMatrix, distCoeffs, rvec, …