This file contains hidden or 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
#pragma once | |
#include <cmath> | |
// https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm | |
template <typename T> | |
class WelfordMeanStddevCalculator { | |
public: | |
WelfordMeanStddevCalculator() = default; | |
virtual ~WelfordMeanStddevCalculator() = default; |
This file contains hidden or 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
#define MODULE_NAME "MY_LIB" | |
// __VA_ARGS__ 对应宏定义中参数列表的最后一个参数为省略号(也就是三个点) | |
// 加上##的作用在于,当可变参数的个数为0时,这里的##起到把前面多余的","去掉的作用,否则会编译出错 | |
#define error_print(fmt, ...) printf("[ERROR]["MODULE_NAME"](%s|%d)" fmt, __func__, __LINE__, ##__VA_ARGS__) | |
// 单个 # 用来把参数转换成字符串 | |
// ## 是个粘合剂,将前后两部分粘合起来,也就是有“字符化”的意思。但是“##”不能随意粘合任意字符,必须是合法的C语言标示符。在单一的宏定义中,最多可以出现一次“#”或“##”预处理操作符。 |
This file contains hidden or 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
// The Hellinger distance measures the similarity of two probability | |
// distributions Reference: https://en.wikipedia.org/wiki/Hellinger_distance | |
double HellingerDistance( | |
const std::vector<double>& histogram1, | |
const std::vector<double>& histogram2) { | |
const int histogram_size = histogram1.size(); | |
CHECK_GT(histogram_size, 0); | |
CHECK_EQ(histogram_size, histogram2.size()); | |
const double mean1 = | |
std::accumulate(histogram1.begin(), histogram1.end(), 0.0) / |
This file contains hidden or 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
#include <iostream> | |
#include <sstream> | |
#include <iomanip> | |
int main() { | |
for (int i = 0; i < 10; ++i) { | |
std::stringstream ss; | |
ss << std::setfill('0') << std::setw(8) << std::fixed << i << ".txt"; | |
std::cout << ss.str() << std::endl; | |
} |
This file contains hidden or 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 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]) |
This file contains hidden or 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
// 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); |
This file contains hidden or 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
#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"; |
This file contains hidden or 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
// 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, |
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
{Description} | |
""" | |
from __future__ import print_function | |
import os | |
import sys |
This file contains hidden or 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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
import os | |
import sys | |
import argparse | |
import cv2 |