每当我更改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;
}