project points from known 3d points, strange issue

asked 2018-01-04 16:05:57 -0500

antithing gravatar image

I have a set of known 3d world points that i am passing to cv::projectPoints.

I pass in the points along with the camera matrices, and my camera position (converted from Eigen Quaternion and Vector3f). The projected 2d points look good when the camera is rotated, but when translated, they slide in the direction of camera movement. Weirdly, inverting the camera tvec matrix has no effect. I feel like I am missing something simple, but I cannot spot it!

I am doing the following:

std::vector<cv::Point2d> projectedPoints(std::vector<cv::Point3d> objectPoints, cv::Mat rVec, cv::Mat tVec)
{

    std::vector<cv::Point2d> imagePoints;

    cv::projectPoints(objectPoints, rVec, tVec, intrisicMat, distCoeffs, imagePoints);

    return imagePoints;
}

and passing the data as follows:

            Eigen::Quaterniond zQuatRaw(quat.w, quat.y, -quat.z, quat.x); //camera rotation data
            Eigen::Vector3f zPosRaw(translation.ty, -translation.tz, translation.tx); //camera position data

            Eigen::Matrix3d R = zQuatRaw.toRotationMatrix();
            cv::Mat Rr(3, 3, cv::DataType<double>::type);

            cv::eigen2cv(R, Rr);

            cv::Mat rvecR(3, 1, cv::DataType<double>::type);
            cv::Rodrigues(Rr, rvecR);

            cv::Mat tVecc(3, 1, cv::DataType<double>::type);
            cv::eigen2cv(zPosRaw, tVecc);

            //repro points
            if (clickedPoints3d.size() > 0)
            {
                reprojectedUserPnts = projectedPoints(clickedPoints3d, rvecR, tVecc);
            }

Like I said above, camera rotation looks great, the projected points stick in place. Camera translation causes them to slide in the direction of camera movement.

The 3d point coordinates are in cm, as is the camera position.

What could be going wrong here?

Thank you.

edit retag flag offensive close merge delete

Comments

Can you post a sample rotation, translation, and a few points? That was we can replicate and see for ourselves.

Tetragramm gravatar imageTetragramm ( 2018-01-04 17:45:06 -0500 )edit