7

It seems to be possible to correct lens distortion with ffmpeg. According to the manual you can adjust K1 and K2 values. What this means? How to use it correctly?

enter image description here Example still image - captured with a canon 60D and a focal length of 18mm (EFS 18-55mm zoom lens)

4
  • Can you provide a screenshot to use as an example input? ffmpeg -ss 10 -i input -vframes 1 output.png
    – llogan
    Commented Feb 3, 2015 at 18:47
  • @LordNeckbeard, of course :)
    – p2or
    Commented Feb 4, 2015 at 16:31
  • Thanks. What lens are you using?
    – llogan
    Commented Feb 4, 2015 at 16:33
  • @LordNeckbeard lens added to question.
    – p2or
    Commented Feb 4, 2015 at 16:35

2 Answers 2

5
+50

In the manual it says:

To use opencv use the calibration sample (under samples/cpp) from the opencv sources and extract the k1 and k2 coefficients from the resulting matrix.

If you go to the opencv website there's a sample source code for a lens correction program, written in c++, here. You'll have to compile it yourself, after installing OpenCV (sounds like you better put on a pot of coffee). When you run it it will spit out an xml file containing the values for k1 and k2, which you can then use as inputs to the filter.

2
  • Haha - Thanks stib as always! Note: You could also preview k1 and k2 values in Blender. But I'm not sure what these values mean. I'm trying to figure it out :)
    – p2or
    Commented Feb 6, 2015 at 15:10
  • Also, you can obtain the xcenter and ycenter values from the OpenCV camera matrix. You'll need to scale them from their OpenCV pixel coordinates to fractional width and height coordinates for use in ffmpeg. I'm not sure if ffmpeg's coordinate system is the same as OpenCV's, though – that's something to look into.
    – billyjmc
    Commented Jan 6, 2016 at 5:43
1

Rather than using the lenscorrection filter, you would probably get better results with the lensfun filter.

Lensfun has a database entry for the Canon 60D that you're using as well as for various EF-S 18-55mm Canon lenses (apparently there are many).

You can read aboud various details in this post that I made on a similar subject.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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