I am using a stereo camera to triangulate 3d points from rectified images. I then use these points, and the found keypoints, to run solvePnp. I get correspondences like this:
// Find out the 2D/3D correspondences
std::vector<cv::Point3f> list_points3d_model_match; // 3D coordinates found in the scene
std::vector<cv::Point2f> list_points2d_scene_match; // 2D coordinates found in the scene
for (unsigned int match_index = 0; match_index < matchR.size(); ++match_index)
{
cv::Point3f point3d_model = Points3d[matchR[match_index].trainIdx]; // 3D points
cv::Point2f point2d_scene = keyPntsCurrent[matchR[match_index].queryIdx].pt; // 2D point
list_points3d_model_match.push_back(point3d_model); // add 3D point
list_points2d_scene_match.push_back(point2d_scene); // add 2D point
}
Then I run solvePnp:
openCvPnp(list_points2d_scene_match, list_points3d_model_match);
with:
cv::Mat rvec(3, 1, cv::DataType<double>::type);
cv::Mat tvec(3, 1, cv::DataType<double>::type);
cv::Mat tvec2(3, 1, cv::DataType<double>::type);
cv::Mat tvecFinal(3, 1, cv::DataType<double>::type);
int64 t0 = cv::getTickCount();
bool useExtrinsicGuess = true;
int iterationsCount = 100;
float reprojectionError = 0.01;
double confidence = 0.8;
tvec = 0.0;
rvec = 0.0;
cv::solvePnP(p3d, p2d,
cameraMatrix, distCoeffs,
rvec, tvec,
useExtrinsicGuess,
cv::SOLVEPNP_ITERATIVE
);
cv::Mat R;
cv::Rodrigues(rvec, R); // R is 3x3
R = R.t(); // rotation of inverse
tvec2 = -R * tvec; // translation of inverse
cv::Mat T(4, 4, R.type()); // T is 4x4
T(cv::Range(0, 3), cv::Range(0, 3)) = R * 1; // copies R into T
T(cv::Range(0, 3), cv::Range(3, 4)) = tvec2 * 1; // copies tvec into T
// fill the last row of T (NOTE: depending on your types, use float or double)
double *p = T.ptr<double>(3);
p[0] = p[1] = p[2] = 0; p[3] = 1;
std::cout << tvec2 << std::endl;
this runs fine, and gives me returned pose values. BUT when i run it on a video stream where the points are constantly changing as the camera turns, the pose data values stay very low. I assume this is because I am just returning the change between frames? is this right? Or is it that solvePnp is choosing a different zero
point each frame, and this is messing up my values?
How can i run solvePnp on a scene where the 3d points change, and return the additive traveled value of the camera?
Thank you.