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

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


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<Point2f> img_ptsTemp;                      //装载单幅棋盘格角点的像素坐标,长度等于角点个数

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

vector<Point3f> obj_ptsTemp;                       //装载单幅棋盘格角点的世界坐标,长度等于角点个数        
vector<vector<Point3f>> 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<Mat> rotation_vectors;
vector<Mat> 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;








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值