Skip to content

Instantly share code, notes, and snippets.

@rabssm
rabssm / Realtek_8188fu.txt
Last active October 11, 2022 09:12
Install driver for Realtek 8188fu Wifi USB device on Raspberry Pi Stretch - hardware ID Realtek 0bda:f179
# Download correct driver from http://downloads.fars-robotics.net/wifi-drivers/8188fu-drivers/
# For example, for kernel version 4.14.79, download the following driver:
wget http://downloads.fars-robotics.net/wifi-drivers/8188fu-drivers/8188fu-4.14.79-1159.tar.gz
# Extract the driver
tar zxvf 8188fu-4.14.79-1159.tar.gz
# Install the driver
sudo ./install.sh
@rabssm
rabssm / ffmpegtips.txt
Last active June 30, 2023 12:43
ffmpeg tips
# Interpolate video frames for a higher frame rate
ffmpeg -i source.mp4 -filter:v minterpolate -r 25 result.mp4
ffmpeg -i source.mp4 -vf minterpolate=50,tblend=all_mode=average,framestep=2 result.mp4
# Crop a video to the bottom right quarter
ffmpeg -i in.mp4 -filter:v "crop=in_w/2:in_h/2:in_w/2:in_h/2" -c:a copy out.mp4
# Resize a video to half size
ffmpeg -i input.mkv -filter_complex "scale=in_w/2:in_h/2" output.mkv
# Fetch files on remotehost modified within the last 7 days
rsync -av user@remotehost:'`find /home/user/* -mtime -7 -print`' .
@rabssm
rabssm / sky_brightness.py
Last active August 28, 2022 04:18
Measure astronomical sky brightness using a DSLR camera. Program to calculate the sky brightness of a JPEG image of the night sky in magnitude/arcsec^2. Python script.
#!/usr/bin/env python
# Program to calculate the sky brightness of a JPEG image of the night sky
# Assumptions:
# The EXIF data for the image contains the following valid tags:
# ISOSpeedRatings, ApertureValue, ExposureTime
import numpy as np
import argparse
import PIL.Image
@rabssm
rabssm / watermark_image.py
Last active May 5, 2018 14:14
Watermark an image using OpenCV 2 and python.
import cv2
# Read in the image
image_file = 'original.jpg'
image = cv2.imread(image_file)
overlay = image.copy()
output = image.copy()
height, width = image.shape[:2]
# Stamp the image lower right corner and write it
@rabssm
rabssm / spiral_pattern.py
Last active April 28, 2018 11:26
Generate a spiral pattern, moving outwards from the centre position (0,0). Python code.
# Generate a spiral pattern, moving outwards from the centre position (0,0)
# The size parameter sets the size of the spiral "shell"
SIZE = 5
x, y = 0, 0
dx, dy = 0, -1
for i in range(SIZE**2):
if (x == y) or (x < 0 and x == -y) or (x > 0 and x == 1-y):
dx, dy = -dy, dx
@rabssm
rabssm / ImagemagickTips.txt
Last active May 7, 2020 14:56
Imagemagick Tips
# Separate an image into RGB channels. Filenames 1, 2, 3 for red, green and blue respectively
convert image.jpg -channel RGB -separate channels_%d.png
# Convert an image to grayscale
convert image.jpg -set colorspace Gray -separate -average image.png
# Threshold an image
convert -threshold 75 image.jpg image-thresh.jpg
# Combine images using max pixel values of each image
@rabssm
rabssm / picamera_video_timestamp.py
Last active June 18, 2020 16:39
Record video on the raspberry pi camera module with timestamp annotation on each frame
import picamera
import picamera.array
import time, datetime
# Use the motiondetector analyze callback to annotate the video with a UTC time stamp
class MotionDetector(picamera.array.PiMotionAnalysis):
def analyze(self, a):
camera.annotate_text = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]
with picamera.PiCamera() as camera:
@rabssm
rabssm / closestpoint3dlines.py
Last active May 18, 2021 14:20
Find a point that is mutually closest to two or more 3d lines in a least-squares sense. Python code.
# Find a point that is mutually closest to two or more 3d lines in a least-squares sense.
# Based on: https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#In_three_dimensions_2
import numpy as np
# Create two or more 3d lines in the form of a matrix [[x1,y1,z1], [x2,y2,z2]]
lines = []
lines.append(np.asmatrix([[ 4, 0,0], [1,1,4]]))
lines.append(np.asmatrix([[-3,-2,0], [4,2,3]]))
lines.append(np.asmatrix([[ 0, 0,0], [2,2,6]]))
lines.append(np.asmatrix([[ 1, 2,0], [2,0,6]]))
@rabssm
rabssm / closestpoint2dlines.py
Last active April 3, 2018 13:30
Find a point that is mutually closest to two or more lines in a least-squares sense. Python code.
# Find a point that is mutually closest to two or more lines in a least-squares sense.
# Based on: https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection#Nearest_point_to_non-intersecting_lines
import numpy as np
import matplotlib.pyplot as plt
# Create two or more lines in the form of a matrix [[x1,y1], [x2,y2]]
lines = []
lines.append(np.asmatrix([[4, 4], [4, -3]]))
lines.append(np.asmatrix([[3, 2], [10, 2]]))
lines.append(np.asmatrix([[3, 3], [6, 4]]))