Skip to content

Instantly share code, notes, and snippets.

View stfuchs's full-sized avatar

Steffen Fuchs stfuchs

  • Zebra Technologies
  • San Jose, CA
View GitHub Profile
bool
compare (int idx1, int idx2) const
{
bool dist_ok;
if(this->depth_dependent_)
{
Eigen::Vector3f vec = input_->points[idx1].getVector3fMap ();
float z = vec.dot (this->z_axis_);
dist_ok = (fabs ((*plane_coeff_d_)[idx1] - (*plane_coeff_d_)[idx2]) < distance_threshold_ * z * z);
}
@stfuchs
stfuchs / hex2bgr.py
Created December 16, 2015 17:30
snippet to convert hex color list to cv::Scalar vector(bgr)
# example color list:
c = """#e41a1c
#377eb8
#4daf4a
#984ea3
#ff7f00
#ffff33
#a65628
#f781bf
#999999"""
#include <camera_info_manager/camera_info_manager.h>
ros::NodeHandle nh("~");
camera_info_manager::CameraInfoManager mgr(nh);
mgr.setCameraName("camera");
mgr.loadCameraInfo("file://my/camera_info.yaml");
sensor_msgs::CameraInfo info = mgr.getCameraInfo();
@stfuchs
stfuchs / eigen_cheatsheet.cpp
Last active July 12, 2017 15:37
Eigen Geometry Cheat Sheet
#include <Eigen/Geometry>
int main(int argc, char** argv)
{
Eigen::Quaterniond q1(0, 0, 0, 1.);
Eigen::Vector3d t1(1., 0, 1.);
Eigen::Vector3d p1 = q1*Eigen::Vector3d(0,0,0) + t1;
//Isometry if only rotation and translation components
Eigen::Isometry3d tf = Eigen::Translation3d(t1) * q1;
Eigen::Affine3d tf_affine = tf;
import sys
from collections import defaultdict, deque
INVALID = "Invalid"
class Record(object):
SOUND = "neigh"
def __init__(self):
self._next = 0
@stfuchs
stfuchs / rotate_matrix.cpp
Last active October 6, 2017 09:06
Rotate image matrix clockwise inplace
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
/*
* Rotate square matrix by 90 deg clock wise.
*/
template<typename T>
bool rotateMatrix(std::vector< std::vector<T> >& mat)
@stfuchs
stfuchs / packing_my_robot_body.py
Created October 5, 2017 12:07
solving a knapsack problem
#! /usr/bin/env python
import json
import requests
import click
def read_description(url):
"""Read json from url.
:param url: url to access
@stfuchs
stfuchs / function_lookup.cpp
Created October 12, 2017 11:39
Function calls from string config
#include <iostream>
#include <string>
#include <functional>
#include <vector>
#include <unordered_map>
std::vector<std::string> split(const std::string& value, char delim)
{
std::vector<std::string> res;
import numpy as np
import tf.transformations as tft
def quat_to_array(msg):
return np.array([msg.x, msg.y, msg.z, msg.w])
def vec_to_array(msg):
return np.array([msg.x, msg.y, msg.z])
def from_pose_msg(msg):
f1 = lambda x: 1./np.exp(0.1*(x + 80.))
f2 = lambda x: -.26*(x+58)
def weight(i, fs):
return lambda x: np.exp(fs[i](x)) / np.sum([np.exp(f(x)) for f in fs])
def softmax(fs):
return lambda x: np.sum([f(x)*weight(i,fs)(x) for i,f in enumerate(fs)])
softmax([f1,f2])(np.linspace(-80,0))