This scrip allows to correct equirectangular frames to be converted into regular perspective images without distrortion. This will allow pre-trained deep learning models to apply inference on coverted 360 images.
The code was submitted to github by Fuen Wang
The code is downloaded from Githum here
This is a two-step process, In the first step, an equirectangular frame is loaded. In the second step the conversion happens so that
equ = E2P.Equirectangular('src/image.jpg')
img = equ.GetPerspective(FOV, theta, phi, height, width)
In this last step,
-
FOV is the field of view in degrees. For instance, a full frame (360-degree) equirectangular image can be split up in four directions of 90 degrees each.
-
Theta is the Z-axis (horizontal) angle (right positive, left negative)
-
Phi is the vertical angle (up/down, (up direction positive, down direction negative)
-
The height and width is output image dimension
Start by importing the dependacies
import os
import cv2
import Equirec2Perspec as E2P
print('done')
Load a sample image
# Load this image
equ = E2P.Equirectangular('src/test1.JPG')
print('done loading the image')
# Convert the image
img = equ.GetPerspective(120, 150, -15, 720, 1080)
print('done converting the image')
# DStoring the image
cv2.imwrite('output.png',img)