

The model of lens distortion that the lenscorrection filter uses is called poly5, and the value of r d r_d r d (the radius in the original distorted image) is given as a function of r u r_u r u (the radius in the corrected output image) as follows: I tried to use the Hugin lens calibration tool to find suitable values of k 1 k_1 k 1 and k 2 k_2 k 2 . You could reasonably say that this is much worse than the raw image, even though in a sense it is closer to the ideal. $ ffmpeg -i chess-raw.png -vf lenscorrection=k1=-0.227:k2=-0.022 chess-lenscorrection-so.pngĬhessboard corrected with lenscorrection filter using parameters from stack overflow Most of these did not work well at all, but one of them worked somewhat: Obviously I’m not the first person to have this problem, and consequently I found a stack overflow thread where other people had posted various values for the same and slightly different cameras.

It acceps two parameters k 1 k_1 k 1 and k 2 k_2 k 2 , which correspond to a quadratic and cubic correction factor applied to the radius of a pixel from the center of the image.

The lenscorrection filter warps the image to correct for lens distortion according to the supplied parameters appropriate for the camera and lens. My aim is to take this image from the camera, and produce an output that looks (geometrically) like the test image.

If you didn’t know that the test image was a chess board, it wouldn’t be obvious that in real life its all straight lines and right angles.
#FFMPEG FILTER VF VIDEO FROM IMAGES TV#
The photo of the pattern (which was on a TV screen, which is flat), looks like this: Original photo of chessboard pattern To test the various filters, I took a picture of the OpenCV chessboard calibration pattern, which looks like this: OpenCV chessboard pattern It’s also open source, which means it’s yours to do what you want with. It can read and write basically any media format, and also has a selection of filters that can be used to transform videos, some of which seemed relevant to my task. FFMpeg is easy to get started with since it has a CLI and doesn’t require writing any code. I decided to make a first attempt using FFMpeg. This causes the camera to shake violently, which makes for shaky videos.įor this post, I’ll focus on just the first issue of lens distortion.
