Skip to content

Instantly share code, notes, and snippets.

View isarandi's full-sized avatar

István Sárándi isarandi

View GitHub Profile
@isarandi
isarandi / calibrate_camera_intrinsics_checkerboard.py
Created July 25, 2023 17:06
Calibrate camera intrinsics with checkerboard
import glob
import cv2
import numpy as np
def main():
checkerboard_size = (6, 8)
image_paths = glob.glob('checkerboard_images/*.jpg')
@isarandi
isarandi / metrabs_webcam_demo.py
Last active July 26, 2023 10:18
MeTRAbs Webcam Demo
# Requires installing the following via pip
# pip install tensorflow tensorflow_hub transforms3d
# pip install git+https://github.com/isarandi/{cameralib,poseviz,simplepyutils,tensorflow-inputs}.git
import logging
import os
os.environ['OMP_NUM_THREADS'] = '1'
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'
os.environ['KMP_INIT_AT_FORK'] = 'FALSE'
# Copyright (c) 2020 István Sárándi <sarandi@vision.rwth-aachen.de>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
@isarandi
isarandi / tf_procrustes.py
Last active June 12, 2023 12:23
Procrustes transformation, implemented in TensorFlow. Procrustes analysis takes two sets of corresponding points and computes a rigid (or similarity) transformation that aligns them best, in a least square sense.
# Copyright 2021 Istvan Sarandi
# MIT License
# Permission is hereby granted, free of charge, to any person obtaining a copy of this software
# and associated documentation files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
@isarandi
isarandi / parallel_map_as_tf_dataset.py
Last active April 22, 2020 19:18
Parallel input pipeline as a TensorFlow Dataset
def parallel_map_as_tf_dataset(
fun, iterable, *, output_types=None, output_shapes=None, shuffle_before_each_epoch=False,
extra_args=None, n_workers=10, n_epochs=None):
"""Maps `fun` to each element of `iterable` and wraps the resulting sequence as
as a TF Dataset. Elements are processed by parallel workers using multiprocessing.
Args:
fun: A function that takes an element from `iterable` plus `extra_args` and returns a sequence of
numpy arrays.
iterable: An iterable holding the input objects, which can be any Python objects, not just numpy arrays.
@isarandi
isarandi / camera.py
Created June 18, 2018 09:33
Camera class with methods to transform coordinates, transform images, and change parameters intuitively (e.g. zoom, orbit around or turn towards point, center principal point)
import cv2
import numpy as np
class Camera:
def __init__(self, eye_point, rot_matrix_world_to_cam, intrinsic_matrix, distortion_coeffs):
"""Initializes camera.
Args:
eye_point: position of the camera in world coordinates
@isarandi
isarandi / dsm.conf
Created June 12, 2018 18:07
Parsing Tivoli Storage Manager logs for syslog-ng
log {
source { file("/var/log/dsmsched.log" follow-freq(10) flags(no-parse)); };
parser { python(class("TivoliParser")); };
destination(d_syslog_tcp);
};
python {
import re
import dateutil.parser
import socket
@isarandi
isarandi / fail2ban.conf
Last active June 11, 2018 19:34
syslog-ng parser for fail2ban's logfile (parsing for graylog)
source s_fail2ban {
file("/var/log/fail2ban.log" follow-freq(10) flags(no-parse));
};
parser fail2ban-parser {
python(
class("Fail2BanParser")
options("regex", '(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d{3}) (?P<PROGRAM>.+?)\.(?P<type>.+?) +\[(?P<PID>\d+)\]: (?P<level>.+?) +(?P<MSG>.+)')
);
};
@isarandi
isarandi / delete_redundant_extracted.py
Created December 2, 2015 15:36
Sometimes I extract a zip or rar archive and don't care to delete one or the other, so now both the archive and its extracted contents take up disk space. This script hunts for such cases and offers to delete the extracted files. It could be modified to offer to delete the archive instead, too.
# encoding=utf8
import os, zipfile, rarfile, tarfile, shutil
# avoid encoding problems
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def remove_file_or_tree(p):