Skip to content

Instantly share code, notes, and snippets.

@walsvid
walsvid / fit_plane.py
Created March 28, 2022 07:43
fit plane
import numpy as np
import scipy.optimize
def fitPLaneLTSQ(XYZ):
# Fits a plane to a point cloud,
# Where Z = aX + bY + c ----Eqn #1
# Rearanging Eqn1: aX + bY -Z +c =0
# Gives normal (a,b,-1)
# Normal = (a,b,-1)
[rows,cols] = XYZ.shape
@walsvid
walsvid / fitPlane.py
Created March 28, 2022 07:42 — forked from RustingSword/fitPlane.py
least square plane fitting of 3d points
import numpy as np
import scipy.optimize
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
def fitPlaneLTSQ(XYZ):
@walsvid
walsvid / chamfer_distance.py
Created March 28, 2022 07:42 — forked from sergeyprokudin/chamfer_distance.py
Vanilla Chamfer distance computation in NumPy
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]
@walsvid
walsvid / rename-tf.py
Created August 18, 2019 05:51
tensorflow save的时候改名
def rename(self, sess=None, ckpt_path=None, step=None):
# if not sess:
# raise AttributeError('TensorFlow session not provided.')
# print(self.vars)
new_vars = {}
for k,v in self.vars.items():
new_vars[k.replace('meshnet','meshnetmvp2m')] = v
saver = tf.train.Saver(new_vars, max_to_keep=0)
@walsvid
walsvid / myserve.py
Created May 23, 2019 11:22
List my ssh server
#!/usr/bin/env python
import sys
from termcolor import colored, cprint
with open('.ssh/config', 'r') as f:
for line in f:
l = line.strip()
#print('L', l)
if l.startswith('Host '):
@walsvid
walsvid / 3dr2n2_to_mesh.py
Created February 16, 2019 11:42
3DR2N2 voxel to Mesh
import numpy as np
from skimage import measure
vox = np.load('prediction.npy')
vox2 = np.pad(vox, ((1,1),(1,1),(1,1)),'constant', constant_values=0)
verts, faces, normals, values = measure.marching_cubes_lewiner(vox2, 0.0)
with open('3d.obj','w') as d:
for v in verts:
d.write('v {} {} {}\n'.format(v[0],v[1],v[2]))
@walsvid
walsvid / readEXR.py
Created January 14, 2019 14:28 — forked from jadarve/readEXR.py
Extract RGB and depth channels from exr images.
import numpy as np
import OpenEXR as exr
import Imath
def readEXR(filename):
"""Read RGB + Depth data from EXR image file.
Parameters
----------
filename : str
@walsvid
walsvid / makefile
Created December 18, 2018 12:11
Pixel2Mesh Makefile
nvcc = /home/wc/lib/cuda-8.0/bin/nvcc
cudalib = /home/wc/lib/cuda-8.0/lib64
tensorflow = /home/wc/anaconda3/envs/mesh/lib/python2.7/site-packages/tensorflow/include
all: tf_approxmatch_so.so tf_approxmatch_g.cu.o tf_nndistance_so.so tf_nndistance_g.cu.o
tf_approxmatch_so.so: tf_approxmatch_g.cu.o tf_approxmatch.cpp
g++ -std=c++11 tf_approxmatch.cpp tf_approxmatch_g.cu.o -o tf_approxmatch_so.so -shared -fPIC -I $(tensorflow) -lcudart -L $(cudalib) -O2 -D_GLIBCXX_USE_C
@walsvid
walsvid / net.prototxt
Created September 4, 2018 02:44
[attribute net]
name: "ResNet-50"
layer {
name: "data"
type: "Python"
top: "data"
python_param{
module: "python_data_layer"
layer: "AdaptAttributeLayer"
}
@walsvid
walsvid / make.sh
Last active September 7, 2018 06:22
build tf op
#!/usr/bin/env bash
cd ../lib/nndistance
CUDA_ROOT=/home/wc/lib/cuda
TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
TF_LIB=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_lib())')
nvcc -std=c++11 -c -o tf_nndistance_g.cu.o tf_nndistance_g.cu \
-I $TF_INC -I$TF_INC/external/nsync/public -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC