# What values to use for a CGI virtual camera matrix?

I’m generating some virtual camera captures made with a 3d cgi software to test my code with zero issues introduced by the camera itself, such as defocus, noise and lens distortion.

Such 3d cameras have zero distortion and have a field of view in degrees values or equivalent lens millimeters. These are not values set for X and Y separately, instead an aspect ratio for the rendered images is used.

What values should I supply to the OpenCV camera matrix?

use HFoV (angle) and width (pixels). DFoV and diagonal analogously. assume fx = fy = f, i.e. square pixels.

\begin{align*} f &= \frac{0.5\cdot \text{width}}{\tan(0.5 \cdot \text{HFoV})} \\ c_x &= (\text{width} - 1) \cdot 0.5 \\ c_y &= (\text{height} - 1) \cdot 0.5 \\ \end{align*}

typical values for f are in the range of 500-2000 for common camera resolutions and FoVs, larger for more resolution (same FoV), larger for narrower FoV (same res).

for distortion coefficients, use all 0. four or five coefficients is the minimum.

Thanks. I’m not faimilar with those values. The function for specifying the camera distortion seems to expect a matrix, not f, cx, cy values.

those values go in that matrix.

C = \begin{pmatrix} f_x & 0 & c_x \\ 0 & f_y & c_y \\ 0 & 0 & 1 \end{pmatrix}
1 Like

The matrix format of [[value,vaue,value][value,vaue,value][value,vaue,value]] , is each sublist a row of the matrix?