Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-06T15:10:10.043Z
Answers.Text: 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 :)
Answers.UserDisplayName: p2or
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-06T05:43:58.867Z
Answers.Text: 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.
Answers.UserDisplayName: billyjmc
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-02-06T05:39:48.027Z
Answers.LastActivityDate: 2015-02-06T05:39:48.027Z
Answers.UserDisplayName: stib
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-03-25T09:49:06.717Z
Answers.LastActivityDate: 2020-03-25T09:49:06.717Z
Answers.UserDisplayName: hedgepigdaniel
Body: <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>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-02-03T18:47:15.440Z
Comments.Text: Can you provide a screenshot to use as an example input? `ffmpeg -ss 10 -i input -vframes 1 output.png`
Comments.UserDisplayName: llogan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-02-04T16:31:22.357Z
Comments.Text: @LordNeckbeard, of course :)
Comments.UserDisplayName: p2or
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-02-04T16:33:38.520Z
Comments.Text: Thanks. What lens are you using?
Comments.UserDisplayName: llogan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2015-02-04T16:35:04.797Z
Comments.Text: @LordNeckbeard lens added to question.
Comments.UserDisplayName: p2or
Tags: <ffmpeg>
Title: Correct lens distortion with ffmpeg
UserDisplayName: p2or
ThreadText: # 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.
  
  
  ---
  
  