Skip to content

Instantly share code, notes, and snippets.

View smeschke's full-sized avatar

Stephen Meschke smeschke

View GitHub Profile
@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 / 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 / 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 / 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 / count_gear_teeth.py
Last active June 27, 2024 09:41
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 / 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 / paperReconstruct.py
Last active March 24, 2024 07:22
Python script that reconstructs torn sections of paper.
import cv2, numpy as np, random, math
# Find contour edges
# Find the edge that is torn
# use the hough line transform
# create a mask image where the lines and white on a black background
# check if the point is in a white or black region
# Rotate the torn edges
# Measure how much they overlap
# The rotation with the maximum overlap will be how they should align
@smeschke
smeschke / align_scan.py
Last active December 26, 2024 17:25
Aligns a scanned document to find optimal rotation
import cv2
import numpy as np
src = 255 - cv2.imread('/home/stephen/Desktop/I7Ykpbs.jpg',0)
scores = []
h,w = src.shape
small_dimention = min(h,w)
src = src[:small_dimention, :small_dimention]
@smeschke
smeschke / segment_post_it.py
Last active April 26, 2019 16:03
Segment Post-It notes from a white background
# This script will only work if the post it
# notes are on a really white background.
#
# You will have to change the paths to:
# 1. Path to source image
# 2. Path to desktop (or folder to save images)
# https://stackoverflow.com/questions/55832414/extract-a-fixed-number-of-squares-from-an-image-with-python-opencv/55834299?noredirect=1#comment98366082_55834299
import cv2
import numpy as np
@smeschke
smeschke / grabcut.py
Created June 18, 2019 00:08
Applies grabcut using a mask generated with DL
import numpy as np
import cv2
from matplotlib import pyplot as plt
# Load image and mask
img = cv2.imread('/home/stephen/Downloads/bird.jpg')
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
h,w,_ = img.shape
deep_mask = cv2.imread('/home/stephen/Downloads/bird_mask.png',0)
deep_mask = cv2.resize(deep_mask, (w,h))