28
$\begingroup$

In the camera setting in motion tracking, how do I tweak the K1, K2 and K3 value properly. I was told that these values are not necessary to tweak but I do want to adjust it, just for the sake of perfection.

$\endgroup$
  • 3
    $\begingroup$ Do note that the lens distortion will change at different focal lengths. $\endgroup$ – David Sep 6 '14 at 20:37
  • $\begingroup$ There is a pretty good explanation by Sebastian König in his Track, Match, Blend! tutorial, Part 08 at 14:25. $\endgroup$ – Samoth Mar 21 '16 at 21:32
41
$\begingroup$

All camera lenses in the real world create some kind of distortion. CG imagery does not have the imperfections of glass.

Setting the distortion values for the lens is crucial if you are trying to do accurate scene reconstruction and integration with 3D generated elements.

To determine the values for a particular lens you can shoot a picture of something you know has straight lines (It doesn't have to be a grid, but it must have straight lines).

Photo of graph paper

Use the annotation tool to draw straight lines to use as reference . Find the beginning and ending points of lines that should be straight and draw a line that connects them (To draw straight lines use CtrlD and Left Mouse Button).

Grease Pencil lines added

Enable Calibration on the Display tab.

Properties Panel in Movie Clip Editor

Play with the K1, K2 settings and distort the pencil lines until they match the curvature of the distorted lines in your image.

To correct Barrel distortion use Negative numbers on K1, for Pincushion use positive values.

Distorted Grease Pencil lines

Settings in Blender 2.8X enter image description here

Keep in mind that most distortion is radial and distorts the image starting from the optical center of the lens (that might not coincide with the center of the image) If you find that the drawn line distort correctly on the top of the frame and not on the bottom (or vice versa, or on one side of the frame and not in the other) you might need to manually find the optical center in the camera settings. The slider on the left will move the optical center horizontally, the one on the right will move it vertically.

enter image description here

To check the result in your image you can use the Render Undistorted option.

Undistorted Graph Paper

Use the same values for images made with the same lens. If you change lenses, you will have to determine the values for each one.

Currently there is no way in blender to use images made with a variable focal length during the shot. In other words don't use a zoom during the shot.

How To Make Use Of The Distortion Information

To use the distortion information in the compositor use a Movie distortion node (not to be confused with the Lens Distortion node) available in Shift + A > Distort > Movie Distortion

The node needs to use the information from the clip you used to determine the distortion.

enter image description here

To create an undistorted version of the image use the node with the Undistort option enabled after the video clip, and before the nodes to combine with the 3D scene.

Undistortion node setup

Depending of your needs, there is another way to use the distortion values of the lens, and that is to leave the video footage alone and apply de distortion to the 3D scene generated in blender. In that case you'd plug the Movie Distortion node to the rendered layers using the Distort option.

Distortion Node Setup

Note

There are currently two choices to undistort.

Distortion Model Popup

Divisions will only give you two parameters to play: K1 and K2. Most lenses can be corrected with these.

For more complex lens distortion.

Polynomial will give you an additional K3.

To understand the difference between the two you can read this IPOL article about division models, but for the mathematically challenged it may suffice to quote:

The main advantage of the division model is the requirement of fewer terms than the polynomial model for the case of severe distortion. Therefore, the division model seems to be more adequate for wide-angle lenses.

for basic info on K1, K2, K3 and image center (or optical axis) read:

https://en.wikipedia.org/wiki/Distortion_(optics)

Blender uses algorithms based on OpenCV. You might want to read more in the following link: https://docs.opencv.org/2.4/doc/tutorials/calib3d/camera_calibration/camera_calibration.html

Other Note When undistorting it is likely that you'll run into problems with the edges of the frame:

It is possible that the undistorted image shows repeated pixels at the edge of the frame:

enter image description here

Or that the edges of the image are missing.

enter image description here

Read these links:

Solve camera motion in Blender: exact camera data or refinement?

Motion tracking. The edges of undistorted footage are cropped, and so are the elements of the 3D scene

For an alternative way to export undistortion information to other software like Nuke, Natron, Fusion, etc. read this link:

https://openvisualfx.com/2020/05/05/nuke-lens-distortion-in-blender-2-90/

and

Why is my footage smearing out towards the border on rendering an image? 3

| improve this answer | |
$\endgroup$
  • 2
    $\begingroup$ @cegaton Could you elaborate K1 and K2? I think this would be a useful addition to this nice answer. $\endgroup$ – p2or Feb 3 '15 at 12:53
  • $\begingroup$ Could you add a few lines of explanations? I never used Blender and just want the k-values of a deformed image but after an hour of searching, I still can not find the buttons you are talking about. :/ $\endgroup$ – Suuuehgi Dec 7 '18 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.