Opened 8 months ago
Last modified 6 months ago
#10912 new defect
d_fov and h_fov not working well when converting equirectangular to rectilinear (v360)
Reported by: | 0kajuna0 | Owned by: | |
---|---|---|---|
Priority: | normal | Component: | undetermined |
Version: | git-master | Keywords: | v360, equirect, rectilinear |
Cc: | 0kajuna0 | Blocked By: | |
Blocking: | Reproduced by developer: | no | |
Analyzed by developer: | no |
Description
Summary of the bug: When trying to convert a 360 frame from equirectangular to rectilinear with the v360 filter, the d_fov (diagonal field of view) works well, but h_fov (horizontal) and v_fov (vertical) don't seem to produce the expected results. The image gets distorted. This also happens if no fov is specified.
How to reproduce:
(tested with recent git master versions)
Equirectangular test file: https://en.wikipedia.org/wiki/Equirectangular_projection#/media/File:Plate_Carr%C3%A9e_with_Tissot's_Indicatrices_of_Distortion.svg
No fov results in a distorted output
% ffmpeg -i in.png -vf v360=e:rectilinear a.png
d_fov results in correct proportions:
% ffmpeg -i in.png -vf v360=e:rectilinear:d_fov=125 b.png
Using h_fov and v_fov to output a different aspect ratio results in a very distorted image
% ffmpeg -i in.png -vf v360=e:rectilinear:h_fov=56:v_fov=112 c.png
We can try to correct this by specifying width and height, but the result is still distorted
% ffmpeg -i in.png -vf v360=e:rectilinear:h_fov=56:v_fov=112:w=1440:h=2880 d.png
As a partial workaround, we can use d_fov and apply a roll and transpose to output a correct vertical ratio
% ffmpeg -i in.png -vf v360=e:rectilinear:d_fov=125:roll=90,transpose=1 e.png
This also works for converting the image back to equirectangular
% ffmpeg -i e.png -vf transpose=2,v360=rectilinear:e:id_fov=125:roll=-90 h.png
Another workaround is to use d_fov and trigonometry to define the output resolution
% ffmpeg -i in.png -vf v360=e:rectilinear:d_fov=125:w=1440:h=2880 f.png
This allows us to output any ratio
% ffmpeg -i in.png -vf v360=e:rectilinear:d_fov=125:w=1440:h=1440 g.png
But unfortunately bringing that back to equirectangular breaks proportions
% ffmpeg -i g.png -vf v360=rectilinear:e:id_fov=125 i.png
Is this a bug or am I doing something wrong?
Change History (7)
comment:1 by , 8 months ago
comment:2 by , 6 months ago
I ran into this problem too, when using ffmpeg to turn an equirectangular panorama into a set of rectilinear snapshots, which I then reconstructed into an equirectangular panoram with Hugin.
ffmpeg -i in.tif \ -vf "v360=input=equirect:output=rectilinear:d_fov=68.84:w=640:h=360:yaw=$Y:pitch=$P:roll=$R" \ out.png
(with $Y $P $R
set to many pseudorandom choices) can be reconstructed to a panorama using Hugin (setting HFOV 60 for its input), where 68.84 = sqrt(60^2 + (60/640*360)^2)
without any glitches, but recombining the outputs from
ffmpeg -i in.tif \ -vf "v360=input=equirect:output=rectilinear:h_fov=60:w=640:h=360:yaw=$Y:pitch=$P:roll=$R" \ out.png
results in weird errors / mismatched overlap / seams.
follow-up: 4 comment:3 by , 6 months ago
I don't see any bug here. Rectilinear output with large field of view does always look distorted.
comment:4 by , 6 months ago
Replying to Michael Koch:
I don't see any bug here. Rectilinear output with large field of view does always look distorted.
Distortion near the edges is expected. That's fine. It's the output width and height ratio that's wrong when not using the d_fov option, and thus the entire image is incorrectly distorted, not just the edges.
follow-up: 6 comment:5 by , 6 months ago
We can try to correct this by specifying width and height, but the result is still distorted
% ffmpeg -i in.png -vf v360=e:rectilinear:h_fov=56:v_fov=112:w=1440:h=2880 d.png
It's still distorted because you did use the wrong value for h.
The correct value would be: h = 1440 / tan(28°) * tan(56°) = 4015
follow-up: 7 comment:6 by , 6 months ago
Replying to Michael Koch:
We can try to correct this by specifying width and height, but the result is still distorted
% ffmpeg -i in.png -vf v360=e:rectilinear:h_fov=56:v_fov=112:w=1440:h=2880 d.png
It's still distorted because you did use the wrong value for h.
The correct value would be: h = 1440 / tan(28°) * tan(56°) = 4015
I agree with that. See comment #1. But shouldn't the output ratio be correct if no w or h are specified?
comment:7 by , 6 months ago
Replying to 0kajuna0:
I agree with that. See comment #1. But shouldn't the output ratio be correct if no w or h are specified?
I'm not sure if it's worth the trouble. If h and w are not specified, then a guess must be made for the h/w ratio. Shall it be 1:1 or 4:3 or 16:9? In my opinion it's best to specify all relevant parameters.
Correction: When using w and h, I was assuming constant pixel per degree measurements, that wouldn't be correct, but shouldn't ffmpeg output at the right dimensions to avoid distortion when w and h are not specified?