1

I have been using ORB feature to do matching of two video frames which suppose to have some common features in advance. Later a transformation is estimated by solvePnPRansac which works relatively well before some modifications were given today. I broke a function into two parts (2 independent functions) today to make one of them extract features and another perform matching. The solvePnPRansac can return transformation results without any problem but it gives only zero matrix after such a modification and I can figure out what is wrong with this.

enter image description here

Here is my code

PNP_RESULT retmotion(pts_obj, pts_img)
{
    float camera_matrix_data[3][3] = {
        { camera.fx, 0, camera.cx },
        { 0, camera.fy, camera.cy },
        { 0, 0, 1 }
    };

    std::cout << "-> solving pnp" << std::endl;
    // Camera matrix.
    const cv::Mat cameraMatrix = cv::Mat(3, 3, CV_64F, camera_matrix_data);
    cv::Mat rmat, tmat, inliers;

    // Solve PnP.
    //cv::solvePnP(pts_obj, pts_img, cameraMatrix, cv::Mat(), rmat, tmat, false, CV_ITERATIVE);
    cv::solvePnPRansac(pts_obj, pts_img, cameraMatrix, cv::Mat(), rmat, tmat, false, 100, 1.0, 100, inliers);

    PNP_RESULT ret1;
    ret1.rvec = rmat;
    ret1.tvec = tmat;
    std::cout << "Rot in SovPnP: " << rmat << std::endl;
    std::cout << "Trsl in SovPnP: " << tmat << std::endl;

    ret1.inliers = inliers.rows;

    return ret1;
}

The PNP_RESULT is simply defined as a structure that contains a rvec, tvec and a inliers. In addition, I have also modified that code to use FLANN matching SURF, SIFT instead of ORB but get nothing changed.

user18441
  • 203
  • 2
  • 11

0 Answers0