OpenCV--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;

}


     
     
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

转载自:https://blog.csdn.net/u011058765/article/details/50856742

贴一个完整版的对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;

}


  
  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47

转载自:https://blog.csdn.net/u011058765/article/details/50856742

猜你喜欢

转载自blog.csdn.net/baidu_38172402/article/details/82428833
今日推荐