The remap function in OpenCV applies a generic geometrical transformation using
a mapping that can be difficult to invert.
In this example we’ll show a solution to the problem of finding an inverse
mapping which is based on a very ingenious idea proposed
here.
The mapping used here transforms the image from an equirectangular projection to
a rectilinear projection and it is applied using the Equirec2Perspec package
which can be found here. The
inverse of this mapping can be calculated analytically but our purpose here is
to show a method that can be used for any mapping.
The test image used in this example can be downloaded from this
link.
The GetPerspective method was modified to return the mappings that we’ll
need later on. It just returns the projection plus the maps used as arguments to
the remap function.
Now we would like to go back from the rectilinear projection to the
equirectangular projection. For this we need to estimate the inverse mapping
using the very clever idea mentioned at the beginning.
Tree creation took 17.52 seconds
Tree query took 24.44 seconds
Weighted sums took 525.04 seconds
The last step is to apply the remap function to the rectilinear projection using
the inverse maps. The output is cropped for aesthetic reasons.