Skip to content

Instantly share code, notes, and snippets.

@sgarciav
sgarciav / bagfile2images.launch
Last active July 2, 2018 23:24
ROS launch file for extratcting images from a bag file.
<launch>
<arg name="IMAGE_TOPIC" default="/camera/image_raw"/>
<arg name="FILENAME" default="test.bag"/>
<arg name="SAVE_PATH" default="ROS_HOME"/>
<arg name="FPS" default="10.0"/>
<node pkg="rosbag" type="play" name="rosbag" required="true" args="$(arg FILENAME)"/>
<node name="extract" pkg="image_view" type="extract_images" respawn="false" required="true" output="screen" cwd="$(arg SAVE_PATH)">
<remap from="image" to="$(arg IMAGE_TOPIC)"/>
<param name="sec_per_frame" value="$(eval (1/arg('FPS')))"/>
@sgarciav
sgarciav / getEllipseAxes.cpp
Created May 8, 2018 14:09
Compute major and minor axes of an ellipse from a covariance matrix.
// Taken from http://www.visiondummy.com/2014/04/draw-error-ellipse-representing-covariance-matrix/
// previously defined
cv::Mat covmat;
// Get the eigenvalues and eigenvectors
cv::Mat eigenvalues, eigenvectors;
cv::eigen(covmat, eigenvalues, eigenvectors);
// Calculate the angle between the largest eigenvector and the x-axis
@sgarciav
sgarciav / GeneralTips.cpp
Created May 9, 2018 04:19
Common items for C++ that I always forget how to do.
// count character occurances in string
std::string s = "the answer; should ;be ;; four";
size_t n = std::count(s.begin(), s.end(), ';');
// Mahalanobis distance
double dist = sqrt((x - u).transposeInPlace() * cov_matrix.inverse() * (x - u)); // untested
@sgarciav
sgarciav / Mount Drive Instructions.md
Created June 22, 2018 21:57
How to mount an external drive.
  1. sudo fdisk /dev/nvme0n1
  2. Choose “n” to create a new partition, then “p” then “1” to create a new primary partition. Just use defaults for the sector numbers. Then “w” to write the data to the disk
  3. sudo mkfs -t ext4 /dev/nvme0n1p1
  4. sudo mkdir /media/nvme0n1p1
  5. sudo mount /dev/nvme0n1p1 /media/nvme0n1p1
  6. sudo chown -R : /media/nvme0n1p1
  7. UID= /media/nvme ext4 defaults 0 0
  8. To find the UUID, enter: sudo blkid
@sgarciav
sgarciav / create_ssl_certificate
Last active October 31, 2018 15:52
Create SSL Certificate
# First create the SSL certificate (.crt file)
# See: https://www.digitalocean.com/community/tutorials/how-to-create-a-self-signed-ssl-certificate-for-apache-in-ubuntu-16-04
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/apache-selfsigned.key -out /etc/ssl/certs/apache-selfsigned.crt
# Then generate the .pfx file
# See: https://www.ssl.com/how-to/create-a-pfx-p12-certificate-file-using-openssl/
openssl pkcs12 -export -out certificate.pfx -inkey privateKey.key -in certificate.crt
# This output file is what you use for the digital signature.
# Cheers.
@sgarciav
sgarciav / InstallCatkinTools.md
Created November 8, 2018 13:57
How to install the catkin_tools package

Get the python-catkin-tools package from apt-get. Execute the following command to download the ROS repositories which contain the .deb for catkin_tools:

    $ sudo sh \
        -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -sc` main" \
        > /etc/apt/sources.list.d/ros-latest.list'
    $ wget http://packages.ros.org/ros.key -O - | sudo apt-key add -

Then execute the following to install catkin_tools:

@sgarciav
sgarciav / get_unique_values.cpp
Last active March 15, 2021 05:28
Determine the unique values in a CV matrix
// function declaration
std::vector<float> unique(const cv::Mat& input, bool sort);
// the actual function
std::vector<float> unique(const cv::Mat& input, bool sort)
{
if (input.channels() > 1 || input.type() != CV_32F)
{
std::cerr << "unique !!! Only works with CV_32F 1-channel Mat" << std::endl;
return std::vector<float>();
@sgarciav
sgarciav / cv_mat_type.cpp
Created March 15, 2021 22:05
Determine the type of cv::Mat
// previously defined
cv::Mat cv_matrix;
std::string r;
int type = cv_matrix.type();
uchar depth = type & CV_MAT_DEPTH_MASK;
uchar chans = 1 + (type >> CV_CN_SHIFT);
switch ( depth ) {
@sgarciav
sgarciav / pass.md
Last active June 13, 2024 18:56
Initialize your password store

About

Summarizing the instructions of the pass tool (as seen on its website).

Getting Started

Installation

Execute: $ sudo apt install pass

@sgarciav
sgarciav / docker-compose-rviz.yml
Created June 9, 2021 23:37
docker-compose file to run Rviz inside a Docker container
version: "3.4"
services:
ros-rviz:
build:
context: .
dockerfile: Dockerfile
image: rviz_container:melodic
container_name: rviz_test
network_mode: "host"