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.


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
lenscorrection filter, no values for k1 and k2 seemed to get the effect I want:Negative k1, negative k2:

Negative k1, positive k2:

Positive k1, negative k2:

Positive k1, positive k2:

In general:
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:
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).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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With