Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to apply a curve bend in ffmpeg?

Tags:

ffmpeg

I have four cameras each feeding me a different portion of a basketball court. Due to the slight offset of the cameras physical locations and lens distortion around the edges of the camera, I cannot simply stitch the videos together without some kind of correction.

I've looked into ffmpeg's perspective filter, as well as the lenscorrection filter. In the former case it was only able to create a trapezoid, not the curved image I want. In the latter case using negative values to k1 and k2 seemed to be heading in the right direction, but it either disorted the top and bottom of the image to the point of being nonsensical noise, or it zoomed in to the image so much that I lost important details.

For the sample picture below, ultimately I want the midcourt line (the blue vertical line on the right side) to be vertical, and I want the mess of wires on the white desk at the bottom to remain visible and identifiable.

Given a video which looks like the following:

enter image description here

I wish to produce something like the following:

enter image description here

This image was made using the "Curve Bend" filter in GIMP, but I just eye-balled it - so it's not perfect. Ideally once I get the exact parameters the midcourt line will be perfectly vertical

When using the lenscorrection filter, no values for k1 and k2 seemed to get the effect I want:

Negative k1, negative k2:

enter image description here

Negative k1, positive k2:

enter image description here

Positive k1, negative k2:

enter image description here

Positive k1, positive k2:

enter image description here

In general:

  • negative / negative distorted the image beyond recognition
  • negative / positive looked alright, but the midcourt line was off the screen and it wasn't clear if any distortion had been applied
  • positive / negative looked the best, but while the top and bottom curved in the middle of the left and right actually bulged out, leaving the midcourt line distorted
  • positive / positive was the opposite of the desired effect
like image 639
stevendesu Avatar asked Nov 30 '25 07:11

stevendesu


1 Answers

I wrote a post about this subject. Strangely enough I was also trying to undistort video of a basketball court.

There's a few options:

  1. Try to find a standard projection (e.g. fisheye, stereographic, etc) that roughly matches the projection that your camera produces, and look up or measure the field of view of your camera. At that point you can use the new v360 filter to correct the image to a rectilinear projection (which is the one where straight lines in real life remain straight in the image).
  2. Either find a database entry in lensfun for your camera, or create one (there are instructions in their documentation), or send pictures and ask the maintainers to do it. Then you can use the lensfun filter to accurately correct the distortion.

Lensfun is probably the best option if you want it to be accurate, but depending on your camera you might find v360 produces good enough results, and its significantly faster.

like image 158
hedgepigdaniel Avatar answered Dec 05 '25 18:12

hedgepigdaniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!