在矩阵上分配值

时间:2016-10-21 20:51:38

标签: c++ opencv matrix camera-calibration

我遇到了c ++的问题。我的想法是使用预定义的相机校准值填充内在矩阵,除非我似乎没有正确地进行此操作。

Mat intrinsic_Matrix(3,3, CV_64F);
float fx = (4032 * 4)/6.69; //2410.76
float fy = (3024 * 4)/5.55; //2179.45

    float cx = 2016.0;
    float cy = 1512.0;

    cout << intrinsic_Matrix << endl;

    cout << endl;

    intrinsic_Matrix.at<float>(0,0) = fx;
    intrinsic_Matrix.at<float>(0,1) = 0.0;
    intrinsic_Matrix.at<float>(0,2) = cx;

    intrinsic_Matrix.at<float>(1,0) = 0.0;
    intrinsic_Matrix.at<float>(1,1) = fy;
    intrinsic_Matrix.at<float>(1,2) = cy;

    intrinsic_Matrix.at<float>(2,0) = 0.0;
    intrinsic_Matrix.at<float>(2,1) = 0.0;
    intrinsic_Matrix.at<float>(2,2) = 1.0;

    cout << intrinsic_Matrix << endl;
    calibrateCamera(frameWorldPoints, bothImagePoints, cvSize(referimages[0].image.cols, referimages[0].image.rows), intrinsic_Matrix, distortion_coeffs, rvecs, tvecs, CV_CALIB_USE_INTRINSIC_GUESS);

两张照片的输出都没什么意义。看起来我正在查看指针值或未初始化的值。此外,opencv抛出了一个不正确的内在矩阵&#34;例外,当我尝试校准它时,我确定并不是因为我打错了。

1 个答案:

答案 0 :(得分:3)

使用64F初始化MAT但使用浮点数。如下更改为32F

Mat intrinsic_Matrix(3,3, CV_64F);
double fx = (4032 * 4)/6.69; //2410.76
double fy = (3024 * 4)/5.55; //2179.45

double cx = 2016.0;
double cy = 1512.0;

cout << intrinsic_Matrix << endl;

cout << endl;

intrinsic_Matrix.at<double>(0,0) = fx;
intrinsic_Matrix.at<double>(0,1) = 0.0;
intrinsic_Matrix.at<double>(0,2) = cx;

intrinsic_Matrix.at<double>(1,0) = 0.0;
intrinsic_Matrix.at<double>(1,1) = fy;
intrinsic_Matrix.at<double>(1,2) = cy;

intrinsic_Matrix.at<double>(2,0) = 0.0;
intrinsic_Matrix.at<double>(2,1) = 0.0;
intrinsic_Matrix.at<double>(2,2) = 1.0;

cout << intrinsic_Matrix << endl;

将所有变量更改为double,将intrinsic_matrix初始化为64F

angular2-google-recaptcha