Skip to content

Instantly share code, notes, and snippets.

View smeschke's full-sized avatar

Stephen Meschke smeschke

View GitHub Profile
@smeschke
smeschke / generate_siteswaps.py
Created March 29, 2019 20:22
Generate Siteswaps
#Takes an integer and returns a siteswap character
def get_char(height):
# If the height is under 10, return the string on the height
if height < 10: return str(height)
# If the height is over 10, return 'a' for 10, 'b' for 11, etc...
else: return chr(height + 87)
# One ball goes high and the others low
for num_balls in range(3,6):
for height in range(6):
siteswap = get_char(height + num_balls)
@smeschke
smeschke / count_gear_teeth.py
Last active June 8, 2021 14:52
Counting gear teeth
import cv2, numpy as np, math
raw_image = cv2.imread('/home/stephen/Desktop/gear6.jpg')
bilateral_filtered_image = cv2.bilateralFilter(raw_image, 5, 175, 175)
# Added median blurring to improve edge detection
median_blurred_images = cv2.medianBlur(bilateral_filtered_image, 5)
edge_detected_image = cv2.Canny(median_blurred_images, 75, 200)
# Switched from RETR_TREE to RETR_EXTERNAL to only extract most outer contours
_, contours, _ = cv2.findContours(edge_detected_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
contour_list = []
for contour in contours:
@smeschke
smeschke / hough_lines
Created March 20, 2019 22:12
Draws a line and hows Hough Space
import cv2, numpy as np, math
# Parameters
num_dots, hw, num_bins = 10, 400, 400
# Read image that has two lines in it
lines = np.zeros((hw,hw), np.uint8)
# Create a row of diagonal dots
space = int(hw / (num_dots+1))
for i in range(num_dots): cv2.circle(lines, (space*(i+1), space*(i+1)), 0, 255, 1)
@smeschke
smeschke / olga.py
Created March 8, 2019 02:15
Draws a spiraling swirl?
import cv2, numpy as np, math, random
# create a list for the particles
num_particles = 25000
particles = np.zeros((num_particles,5), np.float32)
# x, y, angle, size
for i in range(particles.shape[0]): particles[i] = -234,-1234,0,0,i
# define parameters
hw = 1080
@smeschke
smeschke / too_much_pumpkin.py
Created December 29, 2018 00:24
Warps an image to make it look like you didn't eat too much sweets
import cv2, numpy as np
# Read image
img = cv2.imread('/home/stephen/Desktop/vids/me.png')
h,w,_ = img.shape
sf = 1
img = cv2.resize(img, (int(w/sf), int(h/sf)))
img_pristine = img.copy()
# Get clicks from user
@smeschke
smeschke / data_to_midi.py
Created November 9, 2018 17:58
generates midi file based on juggling data
from midiutil import MIDIFile
#if module error, try: sudo-apt get install python-scipy
import cv2
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd
import scipy.signal as signal
#path to source data
data_source = '/home/stephen/Desktop/sound1/sound.csv'
@smeschke
smeschke / sine_fitter.py
Created November 1, 2018 18:38
OpenCV gui to manually fit sine waves
import cv2, math
import numpy as np
import pandas as pd
import scipy
from sklearn import preprocessing
from scipy import signal
import matplotlib.pyplot as plt
@smeschke
smeschke / manual_crop.py
Created October 30, 2018 18:18
Crop rectangle out of image using mouse clicks
import cv2, numpy as np
# Click on one corner of the image,
# then, click on the other corner on the image.
# The image will be cropped and saved into the folder (see below)
# Press 'esc' to quit
# Before you begin, change the path to you own video:
cap = cv2.VideoCapture('/home/stephen/Desktop/track.MP4')
@smeschke
smeschke / smooth_pose_data.py
Last active March 3, 2024 17:57
Smooth Pose Estimation Data
import pandas as pd
import numpy as np
import cv2, os
import scipy
from scipy import signal
import csv
circle_color, line_color = (255,255,0), (0,0,255)
window_length, polyorder = 13, 2
sd = "workout"
@smeschke
smeschke / swap_body_parts.py
Created September 21, 2018 19:49
Ensure that body parts are always in the right places
import pandas as pd
import numpy as np
import cv2, os
import csv
input_source = "/home/stephen/Desktop/me.MP4"
cap = cv2.VideoCapture(input_source)
frame_number = 0
font, scale, colorText, thick = cv2.FONT_HERSHEY_SIMPLEX, .5, (234,234,234), 1
size, color, thickness = 5, (255,255,255), 5