【问题标题】:Having problems with opencv projectPointsopencv projectPoints 有问题
【发布时间】:2015-10-25 00:42:28
【问题描述】:

每当我更改 down_range 变量时,投影图像都不会改变。所有投影点在投影时都具有相同的 Y 值,尽管每个变量(x、y、z、俯仰、滚动和偏航)都发生了变化,但它仍然保持这种状态。有什么我遗漏的吗?

相关代码

//  Vision Target Coordinates
vector<Point3f> objectPoints = getObjectData();

// Create camera matrix for Kinect with focal length found online
Mat cameraMatrix = setCameraMatrix();

vector<Point2f> projectedPoints(objectPoints.size());

//3D Rotation and Translation vectors
Mat rvec1(3,1, cv::DataType<double>::type);
Mat tvec1(3,1, cv::DataType<double>::type);

Mat rvec2(3,1, cv::DataType<double>::type);
Mat tvec2(3,1, cv::DataType<double>::type);

//Initialize to zero
rvec1 = Scalar::all(0);
tvec1 = Scalar::all(0);
rvec2 = Scalar::all(0);
tvec2 = Scalar::all(0);

// Create an image to display projected points
Mat img(height, width,  CV_8UC3);

//get inputs from user, CR, DR, UP, pitch, roll and yaw

tvec1.at<double>(0, 0) = -cross_range*12;   // Xpos (in)
tvec1.at<double>(1, 0) = -down_range*12;    // Ypos (in)
tvec1.at<double>(2, 0) = -up_range*12;      // Zpos (in)
rvec1.at<double>(0, 0) = -pitch*CV_PI/180;;  // X rot (rad)
rvec1.at<double>(1, 0) = -yaw*CV_PI/180;   // Y rot (rad)
rvec1.at<double>(2, 0) = -roll*CV_PI/180;    // Z rot (rad)

projectPoints(objectPoints, rvec1, tvec1, cameraMatrix, distCoeffs, projectedPoints);

vector<Point3f> getObjectData()
{
vector<Point3f> points;

points.push_back(Point3f(-31.0, 10.0, 0.0));
points.push_back(Point3f(31.0, 10.0, 0.0));
points.push_back(Point3f(31.0, -10.0, 0.0));
points.push_back(Point3f(-31.0, -10.0, 0.0));
points.push_back(Point3f(-27.0, 6.0, 0.0));
points.push_back(Point3f(27.0, 6.0, 0.0));
points.push_back(Point3f(27.0, -6.0, 0.0));
points.push_back(Point3f(-27.0, -6.0, 0.0));
points.push_back(Point3f(-103.5, 25.69, 0.0));
points.push_back(Point3f(-41.5, 25.69, 0.0));
points.push_back(Point3f(-41.5, -3.31, 0.0));
points.push_back(Point3f(-103.5, -3.31, 0.0));
points.push_back(Point3f(-99.5, 21.69, 0.0));
points.push_back(Point3f(-45.5, 21.69, 0.0));
points.push_back(Point3f(-45.5, 0.69, 0.0));
points.push_back(Point3f(-99.5, 0.69, 0.0));
points.push_back(Point3f(41.5, 25.69, 0.0));
points.push_back(Point3f(103.5, 25.69, 0.0));
points.push_back(Point3f(103.5, -3.31, 0.0));
points.push_back(Point3f(41.5, -3.31, 0.0));
points.push_back(Point3f(45.5, 21.69, 0.0));
points.push_back(Point3f(99.5, 21.69, 0.0));
points.push_back(Point3f(99.5, 0.69, 0.0));
points.push_back(Point3f(45.5, 0.69, 0.0));

return points;
}

【问题讨论】:

    标签: c++ opencv vision


    【解决方案1】:

    您正在通过欧拉旋转,这是错误的。 转换为Rodrigues,因为OpenCV与欧拉无关。

    【讨论】:

      猜你喜欢
      • 2014-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-14
      • 2021-04-07
      • 2019-01-24
      • 2018-03-13
      • 1970-01-01
      相关资源
      最近更新 更多