solvePnp

贴一个完整版的对solvePnp函数的调用代码

#include<iostream>
#include<opencv2\opencv.hpp>
#include<vector>

using namespace std;
using namespace cv;



int main()
{
    float threeDim[5][3] = { {-11,153,857}, {-10,104,865}, {171,62,708}, {172,50,714}, {-10,28,880} };
    float twoDim[5][2] = { {73,169}, {226,173}, {313,850}, {359,850}, {461,173} };

    vector<Point3f>outDim;
    vector<Point2f>inDim;
    vector<float> distCoeff(0);

    for (int i = 0; i < 5;i++)
    {
        outDim.push_back(Point3f(threeDim[i][0], threeDim[i][1], threeDim[i][2]));
        inDim.push_back(Point2f(threeDim[i][0], threeDim[i][1]));
    }

    Mat cameraMatrix(3,3,CV_32F);
    float tempMatrix[3][3] = { { 2697.6,0 ,597.4 }, { 0, 2682,515.6 }, { 0, 0 ,1} };
    for (int i = 0; i < 3;i++)
    {
        for (int j = 0; j < 3;j++)
        {
            cameraMatrix.at<float>(i, j) = tempMatrix[i][j];
        }
    }

    Mat rvec, tvec;
    solvePnP(outDim, inDim, cameraMatrix, distCoeff, rvec, tvec);

    Rodrigues(rvec, rvec);

    cout << rvec<< endl;
    cout << tvec << endl;

    return 0;

}

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值