# What is the focal length for computer generated pictures?

Hi there,

I am generated some rotated ArUco markers in MatLab and want to get the rotation as normal with OpenCV and C++. The detection algorithm needs of course the camera matrix and the distortion model. The distortion model is easy to have for a perfect camera should be k1,k2,p1,p2,k3 = 0, am I right? The camera matrix offers me a bigger problem... what ist the focal length f (I assume fx=fy). I set the displacements zero: c=cx=cy=0. Now my Camera Matrix should be something like that:

M= [ f, 0, 0;
0, f, 0;
0, 0, 1]

Can anybody tell me, what focal length should be used? In meanwhile I tried to calibrate it with a perfect picture of the (in my case) CharUco Board. (For the CharUco board is an additional avg_reprojection_error, I guess this should be also 0?)

I hope you can help me :) Greetings Sarah

edit retag close merge delete

Sort by » oldest newest most voted Well, cx and cy should be width/2 and height/2 respectively.

How did you generate them? Is it just perfectly flat, square image? Or did you do any perspective transforms?

If you have a perfectly flat, square marker, then just figure out how wide the marker should be (in a length unit such as inches or meters), how wide it is (in pixels), and how far you want it to be from the camera (in the same length unit).

You use the distance and width to figure out what the angle of the markers is, then from there figure out what the whole camera Field of View (FOV) is. Then you use the equation HERE (The horizontal one if you're using width) with h = number of columns in the image. That gives you f.

more

Thank you very much!!! That is exactly what I am looking for and it worked perfectly :-). Do you know how to handle with a perspective transform? At the moment I only rotate the Z-Axis, but a rotation on the Y or X-Axis would be also interesting?

Well, the same deal. You figure out what angle it covers. The geometry gets more complicated since the triangle's base tilts relative to the camera.

Or better, you just keep the same focal length (since that typically doesn't change), and let the size of the marker determine the depth.

Official site

GitHub

Wiki

Documentation