Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/164.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenCV CalibleCamera不';t收敛到正确的解决方案(投影仪校准)_C++_Opencv_Camera Calibration - Fatal编程技术网

C++ OpenCV CalibleCamera不';t收敛到正确的解决方案(投影仪校准)

C++ OpenCV CalibleCamera不';t收敛到正确的解决方案(投影仪校准),c++,opencv,camera-calibration,C++,Opencv,Camera Calibration,我正在尝试使用cv::calibleCamera校准摄像头+投影仪系统。虽然它有时似乎有效,但在许多情况下,估计的解决方案似乎与正确的解决方案相差甚远 下面是一个代码示例,它显示了问题(包括所有数据,因此它非常大) 所以,在对象和图像点之间,每个对应点有一条直线 如果需要更多信息,请发表评论。我的建议是在摄像机校准过程中使用不同的非共面的钻机(表面)。opencv使用的算法肯定需要至少两个不同的视图来执行良好的校准。如果可能,提供几个不同角度的视图(2只是一个起点,10是可取的)。我现在不是10

我正在尝试使用
cv::calibleCamera
校准摄像头+投影仪系统。虽然它有时似乎有效,但在许多情况下,估计的解决方案似乎与正确的解决方案相差甚远

下面是一个代码示例,它显示了问题(包括所有数据,因此它非常大)

所以,在对象和图像点之间,每个对应点有一条直线


如果需要更多信息,请发表评论。

我的建议是在摄像机校准过程中使用不同的非共面的钻机(表面)。opencv使用的算法肯定需要至少两个不同的视图来执行良好的校准。如果可能,提供几个不同角度的视图(2只是一个起点,10是可取的)。我现在不是100%确定,但我认为非平面要求是必要条件,即共面视图无法获得良好结果(因为事实上,它们仅根据比例因子不同,所以在某些情况下,我们可以说它们在投影几何体方面是同构的)


对投影误差的一个评论——在测试案例中,大约是0.65,这似乎是准确的。。。但这里有一个棘手的部分-因为我们只使用一个装备来校准相机,所以根据定义,当opencv重新投影回原点时,它只有一个要重新投影的曲面。换句话说,校准误差很小,并且大于零只是因为存在噪声给定点的投影。

所以您在某些时候获得了正确的参数?您是否尝试过用猜测和使用CV\u CALIB\u USE\u Injective\u guess初始化相机矩阵?在过去,我使用matlab摄像机校准工具箱也取得了更大的成功,也许可以与您在那里得到的结果进行比较。是的,有时我会得到正确的参数(内在和外在)。在我的实际实现中,我使用了
initCameraMatrix2D
作为初始猜测-这在某些情况下似乎可以改善它,但仍然经常发生。我还试图将其行为与matlab校准工具箱进行比较,但无法找出如何直接输入我的通信(如果你能给我一个提示,那也太棒了)。“那么你有时会得到正确的参数?”-思考后:我有时会使用不同的数据获得正确的参数-希望这不会太含糊如果我理解正确,您尝试仅使用一个装备(一个表面)校准相机?如果是,恐怕您需要至少两个非平面表面及其投影才能成功校准。一台钻机是不够的,即使从理论上讲也是如此。因此,这不是点的问题(在您的示例125中),而是不同视图的使用。和offtopic:+1,获取可直接粘贴到visual studio以测试问题的示例。@marol:谢谢您的评论。事实上,这是我一直在思考的一件事——很高兴有一个明确的答案。但我仍然想知道,为什么当我试图从不同的距离捕获模式时,校准没有起作用。由于景深的原因,我只能将它移动约10厘米。我想运动越多效果越好?我一定会在周一尝试,并给你反馈-如果这能解决问题,你也可以将其作为答案发布,这样我就可以接受。似乎这就是问题所在。如果有人想要更多细节=>Zhang描述了他工作中的一些问题()
#include <opencv2/core/core.hpp>
#include <opencv2/calib3d/calib3d.hpp>

#include <iostream>
#include <vector>

cv::Mat calculateTransformation(cv::Mat translationVec, cv::Mat rotationVec) {
    cv::Mat rotationMat3x3;
    cv::Rodrigues(rotationVec, rotationMat3x3);
    cv::Mat rotationMat = cv::Mat::eye(4, 4, CV_64F);
    rotationMat3x3.copyTo(rotationMat(cv::Rect(0, 0, 3, 3)));

    cv::Mat translationMat = cv::Mat::eye(4, 4, CV_64F);
    translationVec.copyTo(translationMat(cv::Rect(3, 0, 1, 3)));

    return translationMat * rotationMat;
}

int main() {
    std::vector<cv::Point2f> image_points;
    std::vector<cv::Point3f> object_points;

    image_points.push_back(cv::Point2f(400.0f, 940.0f));
    image_points.push_back(cv::Point2f(480.0f, 940.0f));
    image_points.push_back(cv::Point2f(560.0f, 940.0f));
    image_points.push_back(cv::Point2f(640.0f, 940.0f));
    image_points.push_back(cv::Point2f(720.0f, 940.0f));
    image_points.push_back(cv::Point2f(800.0f, 940.0f));
    image_points.push_back(cv::Point2f(880.0f, 940.0f));
    image_points.push_back(cv::Point2f(960.0f, 940.0f));
    image_points.push_back(cv::Point2f(1040.0f, 940.0f));
    image_points.push_back(cv::Point2f(1120.0f, 940.0f));
    image_points.push_back(cv::Point2f(1200.0f, 940.0f));
    image_points.push_back(cv::Point2f(1280.0f, 940.0f));
    image_points.push_back(cv::Point2f(400.0f, 860.0f));
    image_points.push_back(cv::Point2f(480.0f, 860.0f));
    image_points.push_back(cv::Point2f(560.0f, 860.0f));
    image_points.push_back(cv::Point2f(640.0f, 860.0f));
    image_points.push_back(cv::Point2f(720.0f, 860.0f));
    image_points.push_back(cv::Point2f(800.0f, 860.0f));
    image_points.push_back(cv::Point2f(880.0f, 860.0f));
    image_points.push_back(cv::Point2f(960.0f, 860.0f));
    image_points.push_back(cv::Point2f(1040.0f, 860.0f));
    image_points.push_back(cv::Point2f(1120.0f, 860.0f));
    image_points.push_back(cv::Point2f(1200.0f, 860.0f));
    image_points.push_back(cv::Point2f(1280.0f, 860.0f));
    image_points.push_back(cv::Point2f(400.0f, 780.0f));
    image_points.push_back(cv::Point2f(480.0f, 780.0f));
    image_points.push_back(cv::Point2f(560.0f, 780.0f));
    image_points.push_back(cv::Point2f(640.0f, 780.0f));
    image_points.push_back(cv::Point2f(720.0f, 780.0f));
    image_points.push_back(cv::Point2f(800.0f, 780.0f));
    image_points.push_back(cv::Point2f(880.0f, 780.0f));
    image_points.push_back(cv::Point2f(960.0f, 780.0f));
    image_points.push_back(cv::Point2f(1040.0f, 780.0f));
    image_points.push_back(cv::Point2f(1120.0f, 780.0f));
    image_points.push_back(cv::Point2f(1200.0f, 780.0f));
    image_points.push_back(cv::Point2f(1280.0f, 780.0f));
    image_points.push_back(cv::Point2f(400.0f, 700.0f));
    image_points.push_back(cv::Point2f(480.0f, 700.0f));
    image_points.push_back(cv::Point2f(560.0f, 700.0f));
    image_points.push_back(cv::Point2f(640.0f, 700.0f));
    image_points.push_back(cv::Point2f(720.0f, 700.0f));
    image_points.push_back(cv::Point2f(800.0f, 700.0f));
    image_points.push_back(cv::Point2f(880.0f, 700.0f));
    image_points.push_back(cv::Point2f(960.0f, 700.0f));
    image_points.push_back(cv::Point2f(1040.0f, 700.0f));
    image_points.push_back(cv::Point2f(1120.0f, 700.0f));
    image_points.push_back(cv::Point2f(1200.0f, 700.0f));
    image_points.push_back(cv::Point2f(1280.0f, 700.0f));
    image_points.push_back(cv::Point2f(400.0f, 620.0f));
    image_points.push_back(cv::Point2f(480.0f, 620.0f));
    image_points.push_back(cv::Point2f(560.0f, 620.0f));
    image_points.push_back(cv::Point2f(640.0f, 620.0f));
    image_points.push_back(cv::Point2f(720.0f, 620.0f));
    image_points.push_back(cv::Point2f(800.0f, 620.0f));
    image_points.push_back(cv::Point2f(880.0f, 620.0f));
    image_points.push_back(cv::Point2f(960.0f, 620.0f));
    image_points.push_back(cv::Point2f(1120.0f, 620.0f));
    image_points.push_back(cv::Point2f(1040.0f, 620.0f));
    image_points.push_back(cv::Point2f(1200.0f, 620.0f));
    image_points.push_back(cv::Point2f(1280.0f, 620.0f));
    image_points.push_back(cv::Point2f(400.0f, 540.0f));
    image_points.push_back(cv::Point2f(480.0f, 540.0f));
    image_points.push_back(cv::Point2f(560.0f, 540.0f));
    image_points.push_back(cv::Point2f(640.0f, 540.0f));
    image_points.push_back(cv::Point2f(720.0f, 540.0f));
    image_points.push_back(cv::Point2f(800.0f, 540.0f));
    image_points.push_back(cv::Point2f(880.0f, 540.0f));
    image_points.push_back(cv::Point2f(1200.0f, 540.0f));
    image_points.push_back(cv::Point2f(1120.0f, 540.0f));
    image_points.push_back(cv::Point2f(480.0f, 460.0f));
    image_points.push_back(cv::Point2f(400.0f, 460.0f));
    image_points.push_back(cv::Point2f(560.0f, 460.0f));
    image_points.push_back(cv::Point2f(720.0f, 460.0f));
    image_points.push_back(cv::Point2f(640.0f, 460.0f));
    image_points.push_back(cv::Point2f(800.0f, 460.0f));
    image_points.push_back(cv::Point2f(1120.0f, 460.0f));
    image_points.push_back(cv::Point2f(880.0f, 460.0f));
    image_points.push_back(cv::Point2f(1040.0f, 460.0f));
    image_points.push_back(cv::Point2f(1280.0f, 460.0f));
    image_points.push_back(cv::Point2f(1120.0f, 380.0f));
    image_points.push_back(cv::Point2f(1280.0f, 380.0f));
    image_points.push_back(cv::Point2f(1200.0f, 380.0f));
    image_points.push_back(cv::Point2f(1040.0f, 380.0f));
    image_points.push_back(cv::Point2f(880.0f, 380.0f));
    image_points.push_back(cv::Point2f(800.0f, 380.0f));
    image_points.push_back(cv::Point2f(960.0f, 380.0f));
    image_points.push_back(cv::Point2f(640.0f, 380.0f));
    image_points.push_back(cv::Point2f(720.0f, 380.0f));
    image_points.push_back(cv::Point2f(560.0f, 380.0f));
    image_points.push_back(cv::Point2f(400.0f, 380.0f));
    image_points.push_back(cv::Point2f(480.0f, 380.0f));
    image_points.push_back(cv::Point2f(1120.0f, 300.0f));
    image_points.push_back(cv::Point2f(1040.0f, 300.0f));
    image_points.push_back(cv::Point2f(960.0f, 300.0f));
    image_points.push_back(cv::Point2f(880.0f, 300.0f));
    image_points.push_back(cv::Point2f(800.0f, 300.0f));
    image_points.push_back(cv::Point2f(720.0f, 300.0f));
    image_points.push_back(cv::Point2f(640.0f, 300.0f));
    image_points.push_back(cv::Point2f(560.0f, 300.0f));
    image_points.push_back(cv::Point2f(480.0f, 300.0f));
    image_points.push_back(cv::Point2f(400.0f, 300.0f));
    image_points.push_back(cv::Point2f(1280.0f, 220.0f));
    image_points.push_back(cv::Point2f(1200.0f, 220.0f));
    image_points.push_back(cv::Point2f(1120.0f, 220.0f));
    image_points.push_back(cv::Point2f(1040.0f, 220.0f));
    image_points.push_back(cv::Point2f(960.0f, 220.0f));
    image_points.push_back(cv::Point2f(800.0f, 220.0f));
    image_points.push_back(cv::Point2f(720.0f, 220.0f));
    image_points.push_back(cv::Point2f(640.0f, 220.0f));
    image_points.push_back(cv::Point2f(560.0f, 220.0f));
    image_points.push_back(cv::Point2f(480.0f, 220.0f));
    image_points.push_back(cv::Point2f(400.0f, 220.0f));
    image_points.push_back(cv::Point2f(1280.0f, 140.0f));
    image_points.push_back(cv::Point2f(1200.0f, 140.0f));
    image_points.push_back(cv::Point2f(1040.0f, 140.0f));
    image_points.push_back(cv::Point2f(960.0f, 140.0f));
    image_points.push_back(cv::Point2f(800.0f, 140.0f));
    image_points.push_back(cv::Point2f(720.0f, 140.0f));
    image_points.push_back(cv::Point2f(640.0f, 140.0f));
    image_points.push_back(cv::Point2f(560.0f, 140.0f));
    image_points.push_back(cv::Point2f(480.0f, 140.0f));
    image_points.push_back(cv::Point2f(400.0f, 140.0f));
    image_points.push_back(cv::Point2f(960.0f, 540.0f));
    image_points.push_back(cv::Point2f(1040.0f, 540.0f));
    image_points.push_back(cv::Point2f(960.0f, 460.0f));

    object_points.push_back(cv::Point3f(-0.0671159000000000f, -0.0530089000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0572335000000000f, -0.0531021000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0473920000000000f, -0.0531268000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0375422000000000f, -0.0531293000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0277093000000000f, -0.0532232000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0179416000000000f, -0.0532900000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.00818986000000000f, -0.0533080000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00159555000000000f, -0.0533734000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0113126000000000f, -0.0534102000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0210113000000000f, -0.0534688000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0307716000000000f, -0.0535300000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0404079000000000f, -0.0535600000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0668703000000000f, -0.0429498000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0569997000000000f, -0.0430325000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0471452000000000f, -0.0430930000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0373059000000000f, -0.0431530000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0274813000000000f, -0.0432117000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0176713000000000f, -0.0432687000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.00790218000000000f, -0.0433224000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00190183000000000f, -0.0433762000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0116116000000000f, -0.0434242000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0213028000000000f, -0.0434700000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0310283000000000f, -0.0435404000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0406556000000000f, -0.0436058000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0666877000000000f, -0.0329366000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0568031000000000f, -0.0329860000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0469101000000000f, -0.0330818000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0370300000000000f, -0.0331543000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0272122000000000f, -0.0332004000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0173840000000000f, -0.0332688000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.00759575000000000f, -0.0333343000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00215042000000000f, -0.0334201000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0119054000000000f, -0.0334816000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0215901000000000f, -0.0335390000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0313087000000000f, -0.0336208000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0409288000000000f, -0.0336740000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0664698000000000f, -0.0228786000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0565702000000000f, -0.0229386000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0466851000000000f, -0.0230437000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0367625000000000f, -0.0230813000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0269267000000000f, -0.0231839000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0171296000000000f, -0.0232845000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.00732099000000000f, -0.0232912000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00244503000000000f, -0.0234120000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0121943000000000f, -0.0235079000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0218997000000000f, -0.0235779000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0316661000000000f, -0.0236490000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0413080000000000f, -0.0237153000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0662403000000000f, -0.0127937000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0563243000000000f, -0.0128856000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0464450000000000f, -0.0129539000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0365046000000000f, -0.0130461000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0266992000000000f, -0.0131572000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0168820000000000f, -0.0132217000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.00702858000000000f, -0.0133096000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00273311000000000f, -0.0134175000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0222048000000000f, -0.0135829000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0124779000000000f, -0.0135008000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0319668000000000f, -0.0136414000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0416578000000000f, -0.0137210000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0660230000000000f, -0.00272328000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0560886000000000f, -0.00280125000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0461911000000000f, -0.00292352000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0362558000000000f, -0.00302379000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0264298000000000f, -0.00309841000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0165924000000000f, -0.00321897000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.00674314000000000f, -0.00331641000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0322628000000000f, -0.00369330000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0225310000000000f, -0.00360024000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0558388000000000f, 0.00733873000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0657448000000000f, 0.00744612000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0458967000000000f, 0.00723106000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0261183000000000f, 0.00701760000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0359654000000000f, 0.00710082000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0162843000000000f, 0.00688856000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0228789000000000f, 0.00646718000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.00641300000000000f, 0.00678188000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0131059000000000f, 0.00657206000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0422672000000000f, 0.00628497000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0231953000000000f, 0.0165035000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0425539000000000f, 0.0162757000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0328968000000000f, 0.0163892000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0133982000000000f, 0.0166424000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.00611577000000000f, 0.0168486000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0160094000000000f, 0.0169642000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00368791000000000f, 0.0167334000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0357336000000000f, 0.0171710000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0258655000000000f, 0.0170562000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0456858000000000f, 0.0173090000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0655273000000000f, 0.0175171000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0555765000000000f, 0.0174012000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0235599000000000f, 0.0266047000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0137369000000000f, 0.0267060000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00400251000000000f, 0.0268771000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.00579988000000000f, 0.0269546000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0156666000000000f, 0.0270784000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0255455000000000f, 0.0272245000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0354855000000000f, 0.0273244000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0454115000000000f, 0.0274243000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0553239000000000f, 0.0275921000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0652735000000000f, 0.0276931000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0432836000000000f, 0.0364607000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0335970000000000f, 0.0365698000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0239205000000000f, 0.0367035000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0140970000000000f, 0.0368368000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00436217000000000f, 0.0369936000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0152808000000000f, 0.0372578000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0252343000000000f, 0.0373656000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0351242000000000f, 0.0374961000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0450986000000000f, 0.0376261000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0550835000000000f, 0.0377566000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0649853000000000f, 0.0379110000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0436747000000000f, 0.0466393000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0339311000000000f, 0.0467559000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0144269000000000f, 0.0470150000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00466523000000000f, 0.0471564000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0150279000000000f, 0.0474823000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0248820000000000f, 0.0475522000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0348463000000000f, 0.0476901000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0447968000000000f, 0.0478509000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0547835000000000f, 0.0479670000000000f, 0.0f));
    object_points.push_back(cv::Point3f(-0.0647592000000000f, 0.0481078000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00301477000000000f, -0.00341146000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.0128075000000000f, -0.00350684000000000f, 0.0f));
    object_points.push_back(cv::Point3f(0.00336785000000000f, 0.00670002000000000f, 0.0f));

    std::vector<std::vector<cv::Point2f>> all_image_points;
    all_image_points.push_back(image_points);
    std::vector<std::vector<cv::Point3f>> all_object_points;
    all_object_points.push_back(object_points);

    cv::Mat camera_mat = cv::Mat::eye(3, 3, CV_64F);
    cv::Mat dist_coeffs = cv::Mat::zeros(4, 1, CV_64F);
    std::vector<cv::Mat> rvecs;
    std::vector<cv::Mat> tvecs;

    double reprojection_error = cv::calibrateCamera(all_object_points, all_image_points, cv::Size(1920, 1080), camera_mat, dist_coeffs, rvecs, tvecs);
    std::cout << "Reprojection error: " << reprojection_error << std::endl;

    cv::Mat transformation = calculateTransformation(tvecs.front(), rvecs.front());
    cv::Mat origin = cv::Mat::zeros(4, 1, CV_64F);
    origin.at<double>(3, 0) = 1.0;
    std::cout << "distance to board: " << cv::norm(transformation * origin) << std::endl;

    return 0;
}
plot3([image_points(1,:);object_points(1,:) * 10000], [image_points(2,:);object_points(2,:) * -10000], [zeros(1, 125); ones(1, 125)], 'b-')