如何找到用于增强现实的相机矩阵?

问题描述:

我想在摄像机的x,y,z米处增加一个虚拟对象. OpenCV具有摄像机校准功能,但我不知道如何精确地以米为单位

I want to augment a virtual object at x,y,z meters wrt camera. OpenCV has camera calibration functions but I don't understand how exactly I can give coordinates in meters

我尝试在Unity中模拟相机,但没有得到预期的结果.

I tried simulating a Camera in Unity but don't get expected result.

我将投影矩阵设置如下,并在z = 2.415 + 0.5处创建一个单位立方体. 其中2.415是眼睛与投影平面之间的距离(针孔相机型号) 由于立方体的面在前裁剪平面上并且其尺寸为单位,因此它不应该覆盖整个视口吗?

I set the projection matrix as follows and create a unit cube at z = 2.415 + 0.5 . Where 2.415 is the distance between the eye and the projection plane (Pinhole camera model) Since the cube's face is at the front clipping plane and it's dimension are unit shouldn't it cover the whole viewport?

    Matrix4x4 m = new Matrix4x4();
    m[0, 0] = 1;
    m[0, 1] = 0;
    m[0, 2] = 0;
    m[0, 3] = 0;

    m[1, 0] = 0;
    m[1, 1] = 1;
    m[1, 2] = 0;
    m[1, 3] = 0;

m[2, 0] = 0;
    m[2, 1] = 0;
    m[2, 2] = -0.01f;
    m[2, 3] = 0;

    m[3, 0] = 0;
    m[3, 1] = 0;
    m[3, 2] = -2.415f;
    m[3, 3] = 0;

我最终手动测量了视场.知道FOV后,就可以轻松创建投影矩阵.不必担心单位,因为最终投影的形式为(X * d/Z,Y * d/Z).无论X,Y,Z的单位如何,X/Z的比率都保持不变.

I ended up measuring the field of view manually. Once you know FOV you can easily create the projection matrix. No need to worry about units because in the end the projection is of the form ( X*d/Z, Y*d/Z ). Whatever the units of X,Y,Z may be the ratio of X/Z remains the same.