Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions nfov.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
from math import pi
import os

import imageio as im
import numpy as np

def is_file(arg):
if not os.path.isfile(arg):
raise argparse.ArgumentTypeError("An input file does not exist")
return arg

class NFOV():
def __init__(self, height=400, width=800):
self.FOV = [0.45, 0.45]
Expand Down Expand Up @@ -88,9 +97,6 @@ def _bilinear_interpolation(self, screen_coord):
CC = np.multiply(C, np.array([wc, wc, wc]).T)
DD = np.multiply(D, np.array([wd, wd, wd]).T)
nfov = np.reshape(np.round(AA + BB + CC + DD).astype(np.uint8), [self.height, self.width, 3])
import matplotlib.pyplot as plt
plt.imshow(nfov)
plt.show()
return nfov

def toNFOV(self, frame, center_point):
Expand All @@ -104,11 +110,27 @@ def toNFOV(self, frame, center_point):
spericalCoord = self._calcSphericaltoGnomonic(convertedScreenCoord)
return self._bilinear_interpolation(spericalCoord)

def main(args):
img = im.imread(args.pano)
nfov = NFOV(args.tile_height, args.tile_width)
# camera center point (valid range [0,1])
center_point = np.array(args.center_point)
tile = nfov.toNFOV(img, center_point)
im.imwrite(args.output_tile, tile)

# test the class
if __name__ == '__main__':
import imageio as im
img = im.imread('images/360.jpg')
nfov = NFOV()
center_point = np.array([0.5, .5]) # camera center point (valid range [0,1])
nfov.toNFOV(img, center_point)
example_text = '''example:
python .\\nfov.py -i .\\images\\360.jpg -tw 800 -th 400 -o .\\res.jpg
'''
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter, epilog=example_text)
parser.add_argument("-i", "--input_pano", type=is_file, dest="pano", help="A path to input 360 pano", required=True)
parser.add_argument("-c", "--center_point", nargs=2, type=float, default=[0.5, 0.5], help="A camera center [0; 1]")
parser.add_argument("-tw", "--tile_width", type=int, help="A target tile width", required=True)
parser.add_argument("-th", "--tile_height", type=int, help="A target tile height", required=True)
parser.add_argument("-o", "--output_tile", type=str, help="A path to output tile", required=True)

args = parser.parse_args()
main(args)


2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
numpy
imageio