OpenCV3.1.0的calibrateCamera()函数计算相机内参数

        OpenCV3.1.0计算相机内参数的函数calibrateCamera与1.0的cvCalibrateCamera2相比,发生了较大变化,主要是有关参数由Mat变成了Array或ArrayOfArrays ,下面是我运行成功的一个程序:


int boards_num = 40;     // 共40幅棋盘格图像
int board_w = 6;         //6*8个角点
int board_h = 8;         //6*8个角点
int n_board_pts = board_w * board_h;   //每幅图的角点数量
CvSize board_size = cvSize(board_w, board_h);

vector img_ptsTemp;                      //装载单幅棋盘格角点的像素坐标,长度等于角点个数

vector> img_ptsVector;     //装载所有棋盘格角点的像素坐标,长度等于棋盘格数量

vector obj_ptsTemp;                       //装载单幅棋盘格角点的世界坐标,长度等于角点个数        
vector> obj_ptsVector;      //装载所有棋盘格角点的世界坐标,长度等于棋盘格数量

CvSize board_img_size;       //棋盘格所在图像的尺寸


if (getChessCorners(frame, board_size, corners) == 0)

{
for (int i = 0; i < n_board_pts; i++)
{
img_ptsTemp.push_back(Point2f(corners[i].x, corners[i].y));        //加载角点坐标
}

img_ptsVector.push_back(img_ptsTemp);
img_ptsTemp.clear();

cvDrawChessboardCorners(frame, board_size, corners, n_board_pts, 1);
cout << real_boards_num << endl;
}


加载世界坐标:

for (int i = 0, k = 0; i < boards_num; i++)
{
for (int j = 0; j < n_board_pts; j++)
{
obj_ptsTemp.push_back(Point3f((float)(j / board_w), (float)(j % board_w), 0.0));
}

obj_ptsVector.push_back(obj_ptsTemp);
obj_ptsTemp.clear();     //一定要清空,否则会连着前面加载的数据
}


// 摄像机参数
Mat intrinsic_mat;
Mat distortion_coeffs;
vector rotation_vectors;
vector translation_vectors;


calibrateCamera(obj_ptsVector,     
                      img_ptsVector,     
      board_img_size, 
      intrinsic_mat, 
      distortion_coeffs, 
      rotation_vectors,         //若不需要,也可设为cv::noArray(),
      translation_vectors,
      CV_CALIB_RATIONAL_MODEL);


printf("INTRINSIC MATRIX: \n");
cout << intrinsic_mat << endl;

printf("DISTORTION VECTOR: \n");
cout << distortion_coeffs << endl;








你可能感兴趣的:(OpenCV3.1.0的calibrateCamera()函数计算相机内参数)