Search Unity

Creating a calibration matrix based on physical camera parameters

Discussion in 'General Graphics' started by serhanguel, Sep 1, 2021.

  1. serhanguel

    serhanguel

    Joined:
    Jan 7, 2019
    Posts:
    7
    Hi, I want to use the parameters of a physical camera in Unity, i.e., focal length and sensor size, for creating a calibration matrix that I will use to apply a perspective transformation using OpenCV. According to this thread, I calculate the matrix parameters fx and fy in pixels by using the following equations

    fx = f * w / sx
    fy = f * h / sy

    where w,h are the width, height of the image, and sx, sy are sensor size dimensions in x, y directions, respectively. Then I build a 4x4 matrix K like this:

    K =
    [[fx, 0, 0, 0],
    [0, fy, 0, 0],
    [0, 0, 1, 0]
    [0, 0, 0, 1]]

    Are these calculations and the matrix formulation correct? In some formulations, I see two additional parameters cx and cy inserted to K[0,3] and K[1,3] that represent the center of the image where cx=w/2 and cy=h/2. I'm not sure though if the image center is (0,0) or (w/2, h/2). Should I add these?

    Also, I have a 4x4 matrix instead of a 3x3 (also enhanced to 4x4 for the extrinsics matrix E) because I want to get an invertible 4x4 matrix when I compute the camera matrix P=KE. I need the inverse because I will use this to get from image coordinates to world coordinates and then reproject to another image for a new camera pose.