Skip to content

Instantly share code, notes, and snippets.

View Hermann-SW's full-sized avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / calcpi.js
Last active May 15, 2023 02:50
gmp-wasm repo "benchmark/calcpi.js" modified to run with nodejs v12.22.12
const DecimalJs = require('decimal.js');
const Big = require('big.js');
const BigInteger = require('big-integer');
// const { init: initGMP, DivMode } = require('../dist/index.umd.js');
const { init: initGMP, DivMode } = require('gmp-wasm');
const piDecimals = require("pi-decimals");
const mpzjs = require("mpzjs");
function nullish(lhs, rhs) {
return (lhs === null || lhs === undefined) ? rhs : lhs
@Hermann-SW
Hermann-SW / Lehman_factor.alg
Created April 25, 2023 20:47
Lehman factoring Algol implementation from 1974 research paper
begin
comment v0.1, only factors sometimes as of now
comment runs with this compiler: https://github.com/JvanKatwijk/algol-60-compiler
$ jff-algol Lehman_factor.alg
$ ./Lehman_factor
32639 3
127
$
;
@Hermann-SW
Hermann-SW / 2x2cropView
Last active April 4, 2023 02:48
Tool to view current Raspberry vX camera crop in correct size preview for setting up scene
#!/bin/bash
if [[ "$1" == "--help" ]]; then echo Format: "$0" "[options]"; exit; fi
read -r w h dummy < <(libcamera-vid --list-cameras | \
grep "([1-9]" | cut -f3 -d: | sed "s#x# #")
dummy=$dummy
libcamera-vid -t 0 --width "$w" --height "$h" --preview=0,0,"$w","$h" "$@"
@Hermann-SW
Hermann-SW / V3crop
Created April 1, 2023 15:31
Tool like GScrop tool, this time for Raspberry v3 camera
#!/bin/bash
if [[ $# -lt 4 ]]; then echo Format: "$0" width height framerate ms [us]; exit; fi
if [[ $# -gt 4 ]]; then SHTR="--shutter"; else SHTR=""; fi
#TODO patch imx708.ko.xz, then activate with rmmod and modprobe
libcamera-hello --list-cameras | grep "([1-9]"
rm -f /dev/shm/tst.pts /dev/shm/tst.h264
sleep 0.2
@Hermann-SW
Hermann-SW / GScropView
Last active March 19, 2023 15:29
GS camera preview corresponding to current GS camera crop settings
#!/bin/bash
if [[ "$1" == "--help" ]]; then echo Format: "$0" "[options]"; exit; fi
read -r w h dummy < <(libcamera-vid --list-cameras | \
tail -1 | cut -f2 -d/ | sed "s#x# #")
dummy=$dummy
libcamera-vid -t 0 --width "$w" --height "$h" --preview=0,0,"$w","$h" "$@"
@Hermann-SW
Hermann-SW / GScrop
Last active May 9, 2024 02:31
tool for playing with Raspberry Pi Global Shutter Camera crop values
#!/bin/bash
# shellcheck disable=SC2154
# (silence shellcheck wrt $cam1 environment variable)
if [[ $# -lt 4 ]]; then echo "Format: [narrow=1] [cam1=1] $0 width height framerate ms [us]"; exit; fi
if [[ "$(( $1 % 2 ))" -eq 1 ]]; then echo "width has to be even"; exit; fi
if [[ "$(( $2 % 2 ))" -eq 1 ]]; then echo "height has to be even"; exit; fi
export SHTR=""; if [[ $# -gt 4 ]]; then SHTR="--shutter"; fi
export workaround=""; if [[ "" != "$(grep '=bookworm' /etc/os-release)" ]]; then workaround="--no-raw"; fi
export d=10; if [[ "" != "$(grep "Revision.*: ...17.$" /proc/cpuinfo)" ]]; then if [[ "$cam1" == "" ]]; then d=6; else d=4; fi; fi
for((m=0; m<=5; ++m))
@Hermann-SW
Hermann-SW / golf.club_head_speed.py
Last active March 5, 2023 14:06
Determine golf club head speed from single raspiraw Raspberry v2 camera high framerate video frame (640x240@383fps, 640x75@1007fps, ...)
#!/usr/bin/python3
#
# Determine club head speed of a golf swing (high framerate video) frame:
# https://forums.raspberrypi.com/viewtopic.php?t=345368#p2070418
import cv2
import numpy as np
from sys import argv, exit
@Hermann-SW
Hermann-SW / 640x75_640x150.picam.py
Created January 14, 2023 01:35
Overlay displaying 640x75 and 640x150 areas for Raspberry v2 camera raspiraw capturing at 1007fps (with 640x75 and 640x150_s tools)
#!/usr/bin/python3
import numpy as np
from picamera import PiCamera
win = 100, 100, 640, 480
picam = PiCamera()
picam.resolution = (640, 480)
@Hermann-SW
Hermann-SW / 640x75_640x150.picam2.py
Created January 14, 2023 01:30
Overlay displaying 640x75 and 640x150 areas for Raspberry v2 camera raspiraw capturing at 1007fps (with 640x75 and 640x150_s tools)
#!/usr/bin/python3
import numpy as np
from picamera2 import Picamera2, Preview
picam2 = Picamera2()
picam2.configure(picam2.create_preview_configuration())
picam2.start_preview(Preview.QTGL, x=100, y=100, width=640, height=480)
picam2.start()
@Hermann-SW
Hermann-SW / BufferlessVideoCapture.py
Last active December 9, 2022 12:59
Allows to always get most recent frame, in case video capture loop has some (computation) delay inside
# Based on: https://stackoverflow.com/questions/43665208/how-to-get-the-latest-frame-from-capture-device-camera-in-opencv/54755738#54755738
#
# Added:
# - configurable delay handling
# - renamed class
# - per frame timestamp output
#
import cv2, threading, time, queue
from sys import argv