This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def load_colmap_sparse_points(points3d_path): | |
'''Load COLMAP points3D.txt as numpy array | |
''' | |
with open(points3d_path, 'r') as f: | |
points_txt = f.readlines()[3:] | |
n_points = len(points_txt) | |
points_np = np.zeros([n_points, 6]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_img_uv_coords(img): | |
""" | |
Get u,v coords for image pixels | |
""" | |
img_height, img_width = img.shape[0], img.shape[1] | |
uv_map = np.zeros([img_height, img_width, 2]) | |
u = np.arange(0, img_height) | |
v = np.arange(0, img_width) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def get_rotation_mat(theta=np.pi, axis=0): | |
# https://en.wikipedia.org/wiki/Rotation_matrix | |
sin = np.sin(theta) | |
cos = np.cos(theta) | |
if axis==0: | |
R = np.asarray([[1, 0, 0], | |
[0, cos, -sin], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
def show_img(img, figsize=(10, 10)): | |
''' | |
Show image using matplotlib | |
Parameters | |
---------- | |
img : array of shape [img_width, img_height, 3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def pdist(X1, X2): | |
"""Computes the matrix of pairwise distances between X1 and X2. | |
The implementation is based on the following observation for matrices: | |
(X1-X2)^2 = X1^2 - 2*X1*X2 + X2^2 | |
Parameters | |
---------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from keras.layers import Input, Dense | |
from keras.models import Model, Sequential | |
def dnn(n_inputs, n_outputs, n_hidden_layers=3, hlayer_size=128, probabilistic=True): | |
"""Defines simple DNN model | |
""" | |
x_input = Input(shape=[n_inputs]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.neighbors import NearestNeighbors | |
def chamfer_distance(x, y, metric='l2', direction='bi'): | |
"""Chamfer distance between two point clouds | |
Parameters | |
---------- | |
x: numpy array [n_points_x, n_dims] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# details: | |
# https://stackoverflow.com/questions/11367736/matplotlib-consistent-font-using-latex/27697390 | |
from matplotlib import rc | |
import matplotlib | |
matplotlib.rcParams['mathtext.fontset'] = 'stix' | |
matplotlib.rcParams['font.family'] = 'STIXGeneral' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Simple point cloud visualization with pyntcloud library | |
""" | |
import pyntcloud as pynt | |
import pandas as pd | |
import numpy as np | |
def show_cloud(xyz, rgb=None, initial_point_size=0.01): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import open3d as o3d | |
import trimesh | |
import numpy as np | |
def ball_pivoting_reconstruction(xyz, radii=None): | |
"""Given a 3D point cloud, get unstructured mesh using ball pivoting algorithm | |
Based on this stack overflow code snippet: | |
https://stackoverflow.com/questions/56965268/how-do-i-convert-a-3d-point-cloud-ply-into-a-mesh-with-faces-and-vertices |