Skip to content

Instantly share code, notes, and snippets.

@insaneyilin
insaneyilin / pcd2bin.py
Created March 12, 2021 05:50
convert pcd to bin file
import numpy as np
import pypcd
filepath='hesai_pandar40p_1593421778.828716.pcd'
pc = pypcd.PointCloud.from_path(filepath)
points = []
for pt in pc.pc_data:
points.append([pt[0], pt[1], pt[2], 0.0])
@insaneyilin
insaneyilin / least_square_line_fitting.cc
Created January 20, 2021 16:00
C++ least square line fitting
// https://www.varsitytutors.com/hotmath/hotmath_help/topics/line-of-best-fit.html
double CalcLineSlope(const std::vector<double>& x,
const std::vector<double>& y) {
const auto n = x.size();
const auto s_x = std::accumulate(x.begin(), x.end(), 0.0);
const auto s_y = std::accumulate(y.begin(), y.end(), 0.0);
const auto s_xx = std::inner_product(x.begin(), x.end(), x.begin(), 0.0);
const auto s_xy = std::inner_product(x.begin(), x.end(), y.begin(), 0.0);
const auto slope = (n * s_xy - s_x * s_y) / (n * s_xx - s_x * s_x);
@insaneyilin
insaneyilin / std_make_heap_example.cc
Created January 1, 2021 02:39
C++ std::make_heap() std::push_heap() std::pop_heap() example
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
void print_vec(std::vector<int> &vec) {
for (auto x : vec) {
std::cout << x << " ";
}
std::cout << "\n";
@insaneyilin
insaneyilin / opencv_draw_dashed_dotted_line.cc
Created January 1, 2021 02:34
Draw Dashed/Dotted line in OpenCV
// reference: https://ddorobot.tistory.com/entry/OpenCV-Draw-DotDash-Line
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include "opencv2/opencv.hpp"
void DrawDashedLine(cv::Mat& img, cv::Point pt1, cv::Point pt2,
@insaneyilin
insaneyilin / cmp_np_arrays.py
Created December 19, 2020 11:15
compare two numpy arrays
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
{Description}
"""
from __future__ import print_function
import os
import sys
@insaneyilin
insaneyilin / hconcat_images.py
Created July 2, 2020 09:58
Concatenate images with python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
import os
import sys
import argparse
import cv2
@insaneyilin
insaneyilin / alias.sh
Last active November 19, 2020 13:12
bash alias
# /etc/profile.d/alias.sh
# https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html
## ls command
alias ls='ls --color=auto'
alias wl='ls | wc -l'
alias l='ls -l --color=auto'
alias lh='ls -lh --color=auto'
alias ll='ls -la --color=auto' # use a long listing format
@insaneyilin
insaneyilin / unix_ts_to_str.cc
Created May 11, 2020 07:26
format unix timestamp to string
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
// e.g. 1584773265.928826
std::stringstream oss;
oss << std::setfill('0') << std::setw(17) << std::fixed
<< std::setprecision(6) << timestamp << ".png";
std::string filename = oss.str();
@insaneyilin
insaneyilin / load_kitti_lidar_bin_file.cpp
Last active April 24, 2020 07:34
A C++ example showing how to load lidar points from .bin file of KITTI dataset.
#include <iostream>
#include <fstream>
#include <string>
// e.g. ./main data_tracking_velodyne/testing/velodyne/0000/000000.bin
int main(int argc, char **argv) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <filepath>\n";
return 1;
}
@insaneyilin
insaneyilin / print_eigen_mat.cpp
Created March 17, 2020 03:11
Print Eigen's Matrix
void PrintEigenMat(const Eigen::Ref<const Eigen::MatrixXd> &x,
const std::string mat_name) {
if (!mat_name.empty()) {
std::cout << mat_name << " =\n";
}
const int rows = x.rows();
const int cols = x.cols();
char buf[200];
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < cols; ++j) {