Iphone 6 camera calibration for OpenCV

后端 未结 1 1942
你的背包
你的背包 2021-02-09 16:11

Im developing an iOS Augmented Reality application using OpenCV. I\'m having issues creating the camera projection matrix to allow the OpenGL overlay to map directly on top of t

相关标签:
1条回答
  • 2021-02-09 16:46

    In my non-OpenCV AR application I am using field of view (FOV) of the iPhone's camera to construct the camera projection matrix. It works alright for displaying the Sun path overlaid on top of the camera view. I don't know how much accuracy you need. It could be that knowing only FOV would not be enough you.

    iOS API provides a way to get field of view of the camera. I get it as so:

    AVCaptureDevice  * camera = ...
    AVCaptureDeviceFormat * format = camera.activeFormat;
    float fieldOfView = format.videoFieldOfView;
    

    After getting the FOV I compute the projection matrix:

    typedef double mat4f_t[16]; // 4x4 matrix in column major order    
    
    mat4f_t projection;
    createProjectionMatrix(projection,
                           GRAD_TO_RAD(fieldOfView),
                           viewSize.width/viewSize.height,
                           5.0f,
                           1000.0f);
    

    where

    void createProjectionMatrix(
            mat4f_t mout, 
            float fovy,
            float aspect, 
            float zNear,
            float zFar)
    {
        float f = 1.0f / tanf(fovy/2.0f);
    
        mout[0] = f / aspect;
        mout[1] = 0.0f;
        mout[2] = 0.0f;
        mout[3] = 0.0f;
    
        mout[4] = 0.0f;
        mout[5] = f;
        mout[6] = 0.0f;
        mout[7] = 0.0f;
    
        mout[8] = 0.0f;
        mout[9] = 0.0f;
        mout[10] = (zFar+zNear) / (zNear-zFar);
        mout[11] = -1.0f;
    
        mout[12] = 0.0f;
        mout[13] = 0.0f;
        mout[14] = 2 * zFar * zNear /  (zNear-zFar);
        mout[15] = 0.0f;
    }
    
    0 讨论(0)
提交回复
热议问题