简体   繁体   中英

How to find correspondence of 3d points and 2d points

I have a set of 3d points in world coordinates and respective correspondences with 2d points in an image. I want to find a matrix that gives me the transformation between these set of points. How can I do this in OpenCV?

cv::solvePnP()是您要寻找的东西,它从3D-2D点对应关系中找到一个对象姿势,并产生一个旋转向量( rvec ),该向量与平移向量( tvec )一起从模型坐标系中获取点相机坐标系。

you can use solvePnP for this:

    // camMatrix based on img size
    int max_d = std::max(img.rows,img.cols);
    Mat camMatrix = (Mat_<double>(3,3) <<
        max_d,   0, img.cols/2.0,
        0,   max_d, img.rows/2.0,
        0,   0,     1.0);

    // 2d -> 3d correspondence
    vector<Point2d> pts2d = ...
    vector<Point3d> pts3d = ...
    Mat rvec,tvec;
    solvePnP(pts3d, pts2d, camMatrix, Mat(1,4,CV_64F,0.0), rvec, tvec, false, SOLVEPNP_EPNP);
    // get 3d rot mat
    Mat rotM(3, 3, CV_64F);
    Rodrigues(rvec, rotM);

    // push tvec to transposed Mat
    Mat rotMT = rotM.t();
    rotMT.push_back(tvec.reshape(1, 1));

    // transpose back, and multiply
    return camMatrix * rotMT.t();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM