forked from JKU-ICG/AOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.py
78 lines (58 loc) · 2.55 KB
/
sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import json
import numpy as np
import os
import cv2
import time
from LFR_utils import read_poses_and_images, pose_to_virtualcamera, init_aos, init_window
import matplotlib.pyplot as plt
from pathlib import Path
import sys
import pyaos.lfr as LFR
def imshow(image, *args, **kwargs):
"""A replacement for cv2.imshow() for use in Jupyter notebooks using matplotlib.
Args:
image : np.ndarray. shape (N, M) or (N, M, 1) is an NxM grayscale image. shape
(N, M, 3) is an NxM BGR color image.
"""
if len(image.shape) == 3:
# Height, width, channels
# Assume BGR, do a conversion
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# Draw the image
plt.imshow(image, *args, **kwargs)
# We'll also disable drawing the axes and tick marks in the plot, since it's actually an image
plt.axis('off')
# Make sure it outputs
# plt.show()
def divide_by_alpha(rimg2):
a = np.stack((rimg2[:,:,3],rimg2[:,:,3],rimg2[:,:,3]),axis=-1)
return rimg2[:,:,:3]/a
if __name__ == '__main__':
if 'window' not in locals() or window == None:
window = init_window() # only init the window once (causes problems if closed and loaded again!)
fov = 32.3443 # 50.815436217896945
# init the light-field renderer
aos = init_aos(1024,1024,fov=fov)
basedatapath = Path(__file__).resolve().parent
# load a digital terrain
aos.loadDEM( os.path.join(basedatapath, '..', 'data', 'zero_plane.obj') )
aos.setDEMTransform([0,0,51])
# load multiple images and corresponding poses
pose_file = os.path.join( basedatapath, '..', 'data', '20210810_conifer_ex2_set2', 'colmap', 'poses', 'RGB.json' )
images_dir = os.path.join( basedatapath, '..', 'data', '20210810_conifer_ex2_set2', 'colmap', 'images', 'cr1024' )
single_images, site_poses = read_poses_and_images( aos,pose_file, images_dir, adjust_mean=False )
center_index = int(round(len(single_images) / 2))
plt.subplot(121)
imshow(np.asarray(single_images[center_index],dtype=np.uint8)), plt.title(f'center image (id={center_index})')
#plt.show()
# compute an integral
integral = aos.render(pose_to_virtualcamera(aos.getPose(center_index)), fov)
tmp = divide_by_alpha(integral) # integrals are 4 channel images, where the last channel (alpha) contains the number of overlapping images
xyz = aos.getXYZ()
#print(xyz)
plt.subplot(122)
imshow(np.asarray(tmp,dtype=np.uint8)), plt.title('integral image (N={})'.format(aos.getViews()))
plt.show()
# cleanup
del aos
del window