Skip to content

Instantly share code, notes, and snippets.

View ES-Alexander's full-sized avatar

ES-Alexander

View GitHub Profile
@ES-Alexander
ES-Alexander / inpaint-stitching-edges.py
Last active October 1, 2021 06:44
Inpaint black regions around stitched images with a blurred effect using the image edge colours.
import cv2
image = cv2.imread('combine.jpg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
mask = (gray == 0).astype('uint8') * 255
blurred = cv2.GaussianBlur(mask, (15,15), 10)
result = cv2.inpaint(image, blurred, 3, cv2.INPAINT_TELEA)
cv2.imshow('result', result)
print('press any key to exit')
@ES-Alexander
ES-Alexander / ssa_encoder.py
Last active November 23, 2023 01:12
SubStation Alpha (SSA/ASS) embedded file encoder
#!/usr/bin/env python3
def parse(file):
''' Generates encoded characters from file byte data.
Encoding is suitable for embedded [Graphics] in SubStation Alpha files.
See here for encoding specification and other details:
http://www.tcax.org/docs/ass-specs.htm
Bytes are split into groups of 6 bits, then 33 is added to each group
@ES-Alexander
ES-Alexander / mavactive.py
Last active April 2, 2024 09:25
An example of using `RC_OVERRIDE`s for basic vehicle control with Pymavlink. Includes a variety of other convenience functions.
from builtins import object
import weakref
from time import sleep
from threading import Thread, Event, Lock
from pymavlink import mavutil
import pymavlink.dialects.v20.ardupilotmega as mavlink
class WriteLockedFile(object):
@ES-Alexander
ES-Alexander / mavlogparse.py
Last active April 23, 2024 09:19
A MAVLink telemetry (.tlog) file parser - similarish to mavlogdump, but (I think) nicer to use and process afterwards
#!/usr/bin/env python3
''' Mavlink telemetry (.tlog) file parser.
Operates as a generator. Allows csv output or listing useful types/fields.
'''
import json
from pathlib import Path
from fnmatch import fnmatch
from pymavlink import mavutil
#!/usr/bin/env python3
from itertools import combinations_with_replacement
from typing import List, Tuple, Generator
VALID_E_SERIES = (3, 6, 12, 24, 48, 96, 192)
def E(m: int) -> Generator[float, None, None]:
""" A generator of IEEE E-series values.
@ES-Alexander
ES-Alexander / whalesong.py
Created February 14, 2022 11:27
Very rough initial analysis of some sound recordings to identify whale songs
from pathlib import Path
from scipy.io import wavfile
from scipy.fft import fft, fftfreq
import matplotlib.pyplot as plt
import numpy as np
path = Path('.') # path to whale song files
files = list(path.glob('*.wav'))
@ES-Alexander
ES-Alexander / voronoi.py
Last active March 25, 2022 17:17
image-based radial voronoi diagram with rectangular bounds
from scipy.spatial import KDTree
import matplotlib.pyplot as plt
import numpy as np
# SETUP
points = np.array([[1,2],[5,9],[-8,-2],[5,-5],[-4,-1]])
xmin, xmax, ymin, ymax = -10, 10, -10, 10
x_resolution = y_resolution = 300
pixel_size = max((xmax-xmin)/x_resolution, (ymax-ymin)/y_resolution)
radius = 3
@ES-Alexander
ES-Alexander / course_monitor.py
Created June 21, 2022 07:18
Minimal example for course tracking of a GPS-enabled MAVLink vehicle, using a low-pass IIR filter for averaging values over time.
#!/usr/bin/env python3
from pymavlink import mavutil, mavlink
class CourseAverager:
MSG_TYPE = 'GLOBAL_POSITION_INT'
def __init__(self, mavlink_connection, request_rate=1, decay_rate=0.95, initial_course=(0, 0)):
self.master = mavlink_connection
self.request_message(request_rate)
@ES-Alexander
ES-Alexander / Mandelbulb.py
Last active December 23, 2022 08:23
A Python-based 3D Mandelbulb Ray-Marcher, with phase shifting
''' Mandelbulb.py
Adapted from
https://github.com/AstroKriel/Mandelbulb/blob/main/python/main.py
EXAMPLE OUTPUT:
https://youtube.com/shorts/f8ek83Z9SFo
Original author: AstroKriel
- Mandelbulb raymarcher
@ES-Alexander
ES-Alexander / process_drawing.py
Last active August 13, 2022 03:41
Clean up a drawing and add a transparent background
'''
Cleans up a drawing, and creates grey, blue, and red variants.
Blue and red are saved with a transparent background.
Grey is saved as single channel.
Author: ES-Alexander
License: MIT (a.k.a. free use, but not my problem if it doesn't work for you)
Created in response to:
https://www.reddit.com/r/opencv/comments/wmyuyh/question_remove_paper_background_from_sketches/