Skip to content

Instantly share code, notes, and snippets.

Avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / GScropView
Last active March 19, 2023 15:29
GS camera preview corresponding to current GS camera crop settings
View GScropView
#!/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 March 17, 2023 16:25
tool for playing with Raspberry Pi Global Shutter Camera crop values
View GScrop
#!/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
for((m=1; m<=5; ++m))
do
if media-ctl -d "/dev/media$m" --set-v4l2 "'imx296 10-001a':0 [fmt:SBGGR10_1X10/${1}x$2 crop:($(( (1440 - $1) / 2 )),$(( (1088 - $2) / 2 )))/${1}x$2]" >/dev/null; then echo -e "/dev/media$m\n"; break; fi
done
libcamera-hello --list-cameras ;echo
rm -f /dev/shm/tst.pts
libcamera-vid --width "$1" --height "$2" --denoise cdn_off --framerate "$3" --save-pts /dev/shm/tst.pts -t "$4" "$SHTR" "$5" -o /dev/shm/tst.h264 -n ;echo
@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, ...)
View golf.club_head_speed.py
#!/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)
View 640x75_640x150.picam.py
#!/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)
View 640x75_640x150.picam2.py
#!/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
View BufferlessVideoCapture.py
# 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
@Hermann-SW
Hermann-SW / bash_.py
Last active December 6, 2022 21:22
Remote control bash from Python
View bash_.py
from subprocess import Popen, PIPE
from sys import argv
import re
stop = "qwertz1234567890ufugUUGUGUgUgUGuGFzR775§%!=%%54321rUF/Rtt8t8TTT4§2hj\n"
bye = ["tschüs","do_widzenia","ahoj","ciao","salut","adieu","vaarwel","farvel"]
byes = re.sub(r"['[]]*", "", str(bye))
cmd = "bash" if len(argv) == 1 else argv[1]
@Hermann-SW
Hermann-SW / bash1.py
Created December 6, 2022 16:08
Execute bash or other executable via Popen(), use .stdin/.stdout to send/recv one line
View bash1.py
from subprocess import Popen, PIPE
from sys import argv
cmd = "bash" if len(argv) == 1 else argv[1]
p = Popen(cmd, stdin=PIPE, stdout=PIPE)
while True:
p.stdin.write(bytes(input(cmd + ": ") + "\n", 'utf-8')); p.stdin.flush()
@Hermann-SW
Hermann-SW / RSA_numbers_factored.py
Last active December 20, 2022 19:23
Provides already factored RSA numbers
View RSA_numbers_factored.py
https://github.com/Hermann-SW/RSA_numbers_factored/
# RSA_numbers_factored.py
#
# v1.9
# remove not needed anymore RSA().__init__()
# add RSA().square_sums()
# manual transpilation to RSA_numbers_factored.js
# new home in RSA_numbers_factored repo python directory
# gist now is pointer to new home only
@Hermann-SW
Hermann-SW / factorial_pow2_odd.tex
Created November 21, 2022 12:42
Factorial, powers and odd numbers …
View factorial_pow2_odd.tex
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{eqnarray*}
(2^n)! \cdot 2 & =& 2^{2^n} \cdot \prod_{j=1}^{n-1} \enspace \prod_{i=2^{n-j-1}+1}^{2^{n-j}}(2i-1)^{j} \\
\end{eqnarray*}
\end{document}