<p>In the manual it says:</p>

<blockquote>
  <p>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.</p>
</blockquote>

<p>If you go to the opencv website there's a sample source code for a lens correction program, written in c++, <a href="http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration/camera_calibration.html" rel="noreferrer">here.</a> 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.</p>

CC BY-SA 3.0
2015-02-06T15:10:10.043Z
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
CC BY-SA 3.0
2016-01-06T05:43:58.867Z
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
CC BY-SA 3.0
2015-02-06T05:39:48.027Z
2015-02-06T05:39:48.027Z
stib
<p>Rather than using the <code>lenscorrection</code> filter, you would probably get better results with the <code>lensfun</code> filter.</p>

<p>Lensfun has a database entry for the <a href="https://github.com/lensfun/lensfun/blob/4877512696c72072065dbee74c77f66f895a5d2e/data/db/slr-canon.xml#L661-L667" rel="nofollow noreferrer">Canon 60D</a> that you're using as well as for various EF-S 18-55mm Canon lenses (apparently there are many).</p>

<p>You can read aboud various details in <a href="https://www.danielplayfaircal.com/blogging/ffmpeg/lensfun/v360/lenscorrection/fisheye/dodgeball/2020/03/24/correcting-lens-distortion-with-ffmpeg.html" rel="nofollow noreferrer">this post</a> that I made on a similar subject.</p>

CC BY-SA 4.0
2020-03-25T09:49:06.717Z
2020-03-25T09:49:06.717Z
hedgepigdaniel
<p>It seems to be possible to correct lens distortion with ffmpeg. According to the <a href="http://www.ffmpeg.org/ffmpeg-all.html#lenscorrection" rel="noreferrer">manual</a> you can adjust K1 and K2 values. What this means? <strong>How to use it correctly?</strong></p>

<p><img src="https://i.sstatic.net/PnJvG.jpg" alt="enter image description here">
<em>Example still image - captured with a canon 60D and a focal length of 18mm (EFS 18-55mm zoom lens)</em></p>

CC BY-SA 3.0
2015-02-03T18:47:15.440Z
Can you provide a screenshot to use as an example input? `ffmpeg -ss 10 -i input -vframes 1 output.png`
llogan
CC BY-SA 3.0
2015-02-04T16:31:22.357Z
@LordNeckbeard, of course :)
p2or
CC BY-SA 3.0
2015-02-04T16:33:38.520Z
Thanks. What lens are you using?
llogan
CC BY-SA 3.0
2015-02-04T16:35:04.797Z
@LordNeckbeard lens added to question.
p2or
<ffmpeg>
Correct lens distortion with ffmpeg
p2or
# Correct lens distortion with ffmpeg

(Asked by: username_0 on 2015-02-01)

It seems to be possible to correct lens distortion with ffmpeg. According to the [manual](http://www.ffmpeg.org/ffmpeg-all.html#lenscorrection) you can adjust K1 and K2 values. What this means? **How to use it correctly?**

![enter image description here](https://i.sstatic.net/PnJvG.jpg)
*Example still image - captured with a canon 60D and a focal length of 18mm (EFS 18-55mm zoom lens)*

**Tags:** ffmpeg

> **Comments:**
> **username_1**: Can you provide a screenshot to use as an example input? `ffmpeg -ss 10 -i input -vframes 1 output.png`  
> **username_0**: @LordNeckbeard, of course :)  
> **username_1**: Thanks. What lens are you using?  
> **username_0**: @LordNeckbeard lens added to question.  

---

## 2 answers

### Answer by username_2 on 2015-02-06. Score: 5

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.](http://docs.opencv.org/doc/tutorials/calib3d/camera_calibration/camera_calibration.html) 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.

> **Comments:**
> **username_0**: Haha - Thanks username_2 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 :)  
> **username_3**: 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.  

---

### Answer by username_4 on 2020-03-25. Score: 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](https://github.com/lensfun/lensfun/blob/4877512696c72072065dbee74c77f66f895a5d2e/data/db/slr-canon.xml#L661-L667) 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](https://www.danielplayfaircal.com/blogging/ffmpeg/lensfun/v360/lenscorrection/fisheye/dodgeball/2020/03/24/correcting-lens-distortion-with-ffmpeg.html) that I made on a similar subject.


---

