Skip to content

Instantly share code, notes, and snippets.

View HViktorTsoi's full-sized avatar

KINO HViktorTsoi

  • BUAA
View GitHub Profile
@HViktorTsoi
HViktorTsoi / write_pcd_binary_format.py
Created February 27, 2025 14:12
Write Nx4 numpy arrary point cloud (x, y, z, intensity) to PCD
def write_pcd_binary(points, filename):
"""
将Nx4的点云数据保存为PCD二进制格式
points: Nx4的numpy array,每行为(x,y,z,intensity)
filename: 保存的文件名
"""
n_points = len(points)
# PCD文件头
header = f"""# .PCD v0.7 - Point Cloud Data file format
@HViktorTsoi
HViktorTsoi / video_cut.desktop
Created February 8, 2025 07:52
A ubuntu utility for quickly cutting video.
# location: /home/xxx/.local/share/applications
[Desktop Entry]
Name=VideoCut
Comment=Fast video cutting tool
Exec=/path/to/video_cut.py %U
Icon=/path/to/icon.png
Terminal=false
Type=Application
@HViktorTsoi
HViktorTsoi / pdf_to_png.desktop
Created February 8, 2025 07:47
An Ubuntu utility for converting PDF file to PNG file.
# location: /home/xxx/.local/share/applications/
[Desktop Entry]
Name=PDF2PNG
Comment=converting pdf to png
Exec=/path/to/pdf_to_png/pdf_to_png.py %U
Icon=/path/to/pdf_to_png.png
Terminal=false
Type=Application
@HViktorTsoi
HViktorTsoi / add_xhost_privilege.sh
Last active September 25, 2024 17:33
Solve error: "This application failed to start because no Qt platform plugin could be initialized, Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb."
# Error imformation:
# No protocol specified
# qt.qpa.xcb: could not connect to display unix:0
# qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
# This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
# Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
# Soultion:
xhost +si:localuser:root
@HViktorTsoi
HViktorTsoi / axis_decimal_decimal.py
Created March 10, 2024 15:19
Matplotlib, set decimal format of axis
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
plt.gca().yaxis.set_major_formatter(mtick.FormatStrFormatter('%.2f'))
@HViktorTsoi
HViktorTsoi / multicolor_legend.py
Created March 1, 2024 17:27
Matplotlib multicolor legend
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.legend_handler import HandlerLineCollection, HandlerNpoints, HandlerBase, HandlerLine2D, HandlerTuple
plot1 = plt.plot([3, 2, 1], [1, 2, 3])
plot2 = plt.plot([1, 2, 3], [3, 2, 1])
multi_color_line = tuple(
[plt.plot([0, 0, 0], color=plt.get_cmap('rainbow')(v)[:3])[0] for v in np.linspace(0.0, 1.0, 5)])
l = plt.legend([multi_color_line, plot1[0], plot2[0]], ['Multiple color 0', 'Color1', 'Color2'],
@HViktorTsoi
HViktorTsoi / get_rosbag_working_dir.py
Created August 22, 2023 14:29
Get the working dir of current rosbag process
import subprocess
def get_process_cwd(process_name):
try:
pid = subprocess.check_output(['pgrep', '-f', process_name]).decode('utf-8').strip().split('\n')[0]
cwd = subprocess.check_output(['pwdx', pid]).decode('utf-8').strip().split(" ")[-1]
return cwd
except subprocess.CalledProcessError:
return None
@HViktorTsoi
HViktorTsoi / AddNoiseToOdometry.py
Created June 15, 2023 06:52
Add accumulated noise to odometry estimation.
def odom_add_noise(poses_poor):
ts_list = []
pose_list = []
for key, pose in sorted(poses_poor.items()):
ts_list.append(key)
pose_list.append(pose)
velocity_integration = []
for idx in range(1, len(pose_list)):
velocity_integration.append(U.INV(pose_list[idx - 1]) @ pose_list[idx])
@HViktorTsoi
HViktorTsoi / slerp.py
Created May 15, 2023 22:57
Linear Pose Interpolation
def trajectory_slerp(evaluate_times, traj_raw_times, traj_raw, order=3):
"""
linear interpolation trajectory
:param evaluate_times: A list of float, the timestamps list at which to evaluate the interpolated poses.
:param traj_raw_times: A list of float, the timestamps list of the input sparse poses
:param traj_raw: A list of np[4x4] matrix, the SE3 matrices of the input sparse poses
:param order: The degree of the spline fit
:return:
"""
assert len(traj_raw_times) == len(traj_raw)
@HViktorTsoi
HViktorTsoi / GTO.py
Created April 21, 2023 07:48
hilti2022 experiment
import copy
import time
import open3d as o3d
import os
from collections import defaultdict
import numpy as np
import numpy.linalg as LA
import gtsam
import tqdm