Skip to content

Instantly share code, notes, and snippets.

View HViktorTsoi's full-sized avatar

KINO HViktorTsoi

  • BUAA
View GitHub Profile
@HViktorTsoi
HViktorTsoi / pc_interpolation.py
Last active October 21, 2019 07:16
Pointcloud interpolation methods
import os
import pandas
import time
import numpy as np
import array
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import cv2
from scipy.interpolate import griddata, Rbf, interpolate
@HViktorTsoi
HViktorTsoi / BarycentricInterpolation.py
Last active November 5, 2019 06:47
numpy implementation of barycentric interpolation from delaunay triangles
import numpy as np
from scipy.spatial import Delaunay
def calc_dis(x1, y1, x2, y2, x3, y3):
return np.sqrt(np.power(x1 - x2, 2) + np.power(y1 - y2, 2)) + \
np.sqrt(np.power(x1 - x3, 2) + np.power(y1 - y3, 2)) + \
np.sqrt(np.power(x2 - x3, 2) + np.power(y2 - y3, 2))
def calc_triangle_area(x1, y1, x2, y2, x3, y3):
return 1 / 2 * ((x1 * y2 - x2 * y1) + (x2 * y3 - x3 * y2) + (x3 * y1 - x1 * y3))
@HViktorTsoi
HViktorTsoi / KITTI projection.py
Last active November 16, 2022 07:12
KITTI Pointcloud front-view projection
import multiprocessing
import os
import numpy as np
import array
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import cv2
from scipy.interpolate import griddata, Rbf, interpolate
from PIL import Image
@HViktorTsoi
HViktorTsoi / mls upsample.cpp
Last active May 26, 2020 14:38
MLS upsample in PCL
#include <iostream>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/ModelCoefficients.h>
#include <cmath>
#include <fstream>
#include <vector>
#include <pcl/filters/passthrough.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/statistical_outlier_removal.h>
@HViktorTsoi
HViktorTsoi / atomic_min.cu
Created May 25, 2020 05:30
atomic min CAS, cuda implementation
__device__ float customAtomicMin( unsigned long long int* address, unsigned long long int newVal )
{
unsigned long long int old = *address, assumed;
if( *((float*)&old ) <= *((float*)&newVal) )
return *((float*)&old);
do
{
assumed = old;
if( *((float*)&assumed) <= *((float*)&newVal) )
@HViktorTsoi
HViktorTsoi / Argsort.cpp
Created June 21, 2020 07:23
C++ STL implementation of Argsort
#include <vector>
#include <algorithm>
/**
* Argsort(currently support ascending sort)
* @tparam T array element type
* @param array input array
* @return indices w.r.t sorted array
*/
template<typename T>
@HViktorTsoi
HViktorTsoi / CartesianProduct.py
Created June 21, 2020 12:14
Cartesian product of x and y array implementation in Numpy
import numpy as np
x = np.arange(10)
y = np.arange(42)
cp = np.transpose([np.tile(x, len(y)), np.repeat(y, len(x))])
@HViktorTsoi
HViktorTsoi / project_points
Created June 25, 2020 13:30
project 3D point to certain plane with parameter A, B, C (w.r.t. Ax+By+Cz=1)
def project_points(x, y, z, a, b, c):
"""
Projects the points with coordinates x, y, z onto the plane
defined by a*x + b*y + c*z = 1
"""
vector_norm = a * a + b * b + c * c
normal_vector = np.array([a, b, c]) / np.sqrt(vector_norm)
point_in_plane = np.array([a, b, c]) / vector_norm
import time
import matplotlib.pyplot as plt
import numpy as np
def get_omega(position):
position_list = []
for line in range(LINES):
new_position = np.copy(position)
@HViktorTsoi
HViktorTsoi / ToRing.py
Last active September 9, 2022 03:11
Any type of LiDAR point cloud to ring-based LiDAR style
import numpy.linalg as LA
import numpy as np
def any_LiDAR_to_ring(pc, num_beams=32, ring_height=8e-4):
"""
convert any type of LiDAR point cloud to ring-based LiDAR style
:param pc: input point cloud, shape of Nx4(x,y,z,intensity)
:param num_beams: number of beams
:param ring_height: the "line width" of a ring
:return: ring-stype point cloud, shape of Nx5(x,y,z,intensity, ring ID)