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

https://imgur.com/dxlo01O

d_fov results in correct proportions:

% ffmpeg -i in.png -vf v360=e:rectilinear:d_fov=125 b.png

https://imgur.com/Ti96A7o

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

https://imgur.com/B0tJctX

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

https://imgur.com/tl6CbJq

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

https://imgur.com/XydgshW

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

https://imgur.com/uNHThfJ

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

https://imgur.com/evVUX5i

This allows us to output any ratio

% ffmpeg -i in.png -vf v360=e:rectilinear:d_fov=125:w=1440:h=1440 g.png

https://imgur.com/OC8pwQE

But unfortunately bringing that back to equirectangular breaks proportions

% ffmpeg -i g.png -vf v360=rectilinear:e:id_fov=125 i.png

https://imgur.com/TP8wXzF

Is this a bug or am I doing something wrong?

Change History (7)

comment:1 by 0kajuna0, 8 months ago

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?

comment:2 by claude, 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.

comment:3 by Michael Koch, 6 months ago

I don't see any bug here. Rectilinear output with large field of view does always look distorted.

in reply to:  3 comment:4 by 0kajuna0, 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.

comment:5 by Michael Koch, 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

in reply to:  5 ; comment:6 by 0kajuna0, 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?

in reply to:  6 comment:7 by Michael Koch, 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.

Note: See TracTickets for help on using tickets.