Skip to content

Instantly share code, notes, and snippets.

View 99991's full-sized avatar

Thomas Germer 99991

  • HHU Düsseldorf
  • Düsseldorf
View GitHub Profile
import shutil
# Remove cache if it exists
try:
shutil.rmtree("__pycache__")
except FileNotFoundError:
pass
try:
with open("/proc/cpuinfo") as f:
@99991
99991 / test.cu
Created July 5, 2024 13:14
Test CUDA
#include <cuda_runtime.h>
#include <iostream>
#define CHECK_CUDA_ERROR(call) \
do { \
cudaError_t err = call; \
if (err != cudaSuccess) { \
std::cerr << "CUDA error at " << __FILE__ << ":" << __LINE__ << " - " \
<< cudaGetErrorString(err) << " (" << err << ")" << std::endl; \
exit(EXIT_FAILURE); \
@99991
99991 / image_alignment.py
Created July 12, 2023 07:39
Example on how to use OpenCV's image alignment/image registration module https://docs.opencv.org/4.8.0/db/d61/group__reg.html
import cv2
import numpy as np
import urllib.request
import os
# Download Tsukuba stereo test images
urls = [
"https://vision.middlebury.edu/stereo/data/scenes2001/data/tsukuba/scene1.row3.col1.ppm",
"https://vision.middlebury.edu/stereo/data/scenes2001/data/tsukuba/scene1.row3.col2.ppm",
]
@99991
99991 / colors.txt
Last active December 14, 2022 21:35
10 easily differentiable colors
Colors:
[[255, 128, 128], [255, 174, 128], [255, 221, 128], [213, 255, 128], [128, 255, 183], [128, 255, 253], [128, 208, 255], [128, 151, 255], [198, 128, 255], [255, 128, 202]]
RGB colors in unit range:
(1.00, 0.50, 0.50), (1.00, 0.68, 0.50), (1.00, 0.87, 0.50), (0.84, 1.00, 0.50), (0.50, 1.00, 0.72), (0.50, 1.00, 0.99), (0.50, 0.82, 1.00), (0.50, 0.59, 1.00), (0.78, 0.50, 1.00), (1.00, 0.50, 0.79)
Colors in hexadecimal:
['#ff8080', '#ffae80', '#ffdd80', '#d5ff80', '#80ffb7', '#80fffd', '#80d0ff', '#8097ff', '#c680ff', '#ff80ca']
@99991
99991 / pyopencl_knn.py
Created December 5, 2022 06:46
KD-Tree query using PyOpenCL to find k nearest neighbors
import numpy as np
import pyopencl as cl
from pymatting import KDTree
import pymatting
import time
source = """
typedef int int32_t;
typedef long int64_t;
import blenderproc as bproc
import numpy as np
bproc.init()
# Create a simple object:
obj = bproc.object.create_primitive("MONKEY")
# Create a point light next to it
light = bproc.types.Light()
@99991
99991 / gpu_usage.py
Last active September 9, 2022 21:40
Get NVIDIA GPU memory usage and find free GPUs using nvidia-smi
import subprocess, getpass
def get_gpu_usage():
"""
Returns a dict which contains information about memory usage for each GPU.
In the following output, the GPU with id "0" uses 5774 MB of 16280 MB.
253 MB are used by other users, which means that we are using 5774 - 253 MB.
{
@99991
99991 / plot_bars.py
Created December 18, 2020 06:44
Plot bar chart with multiple groups of bars with matplotlib pyplot
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
# ugly hack to embed fonts
matplotlib.rc("pdf", fonttype=42)
edgecolor = "black"
bar_scale = 0.8
@99991
99991 / oriented_coloring.py
Last active May 5, 2020 20:54
Calculate the smallest oriented coloring for a directed graph https://en.wikipedia.org/wiki/Oriented_coloring
from z3 import *
import matplotlib.pyplot as plt
import random, math
# pip install z3-solver matplotlib
# do not install z3, that's a different library
random.seed(0)
def find_ordered_coloring(edges, n):
@99991
99991 / hex_grid.py
Created March 2, 2020 19:57
A python code snippet to generate a hexagonal svg grid
import math
class Line:
def __init__(self, x1, y1, x2, y2):
self.x1 = x1
self.y1 = y1
self.x2 = x2
self.y2 = y2
def to_svg(self, style):