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.
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 that shows the lens distortion very clearly (It doesn't have to be a grid but is easier if the image has straight lines).
Use the grease pencil 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).
Enable calibration on the Display tab.
Play with the K1, K2 settings distorting the grease pencil lines until they match the curvature of the distorted lines in your image.
If you find that the 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.
To check the result in your image you can use the Render Undistorted option.
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.
To use the undistorted image in the compositor you should add a Movie Distortion node (ShiftA > Distort > Movie Distortion - with the undistort option enabled) after the video clip, and before the nodes to combine with the 3D scene.
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.
NOTE: There are currently two choices to undistort.
Divisions will olny give you two parameters to play: K1 and K2.
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.
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:
Or that the edges of the image are missing.