Skip to content

Instantly share code, notes, and snippets.

View smeschke's full-sized avatar

Stephen Meschke smeschke

View GitHub Profile
@smeschke
smeschke / snow.py
Created December 5, 2022 13:56
Python/OpenCV script that displays snow
import cv2
import numpy as np
import random
numSnowflakes = 2000
xSize, ySize = 1080, 1920
#cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
#cv2.setWindowProperty("window",cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
import cv2
import numpy as np
import math
imgSize = 600,600, 3
coreCenter = 300,300
coreSize = 50
beltThickness = .045
beltLength = 5025
segmentStart = coreCenter[0], coreCenter[1] + coreSize
import numpy as np
import cv2
import pandas as pd
import numpy.polynomial.polynomial as poly
import math
# Read Source Data
cap = cv2.VideoCapture('/home/stephen/Desktop/ss5_id_412.MP4')
df = pd.read_csv('/home/stephen/Desktop/ss5_id_412.csv')
#Write Video Out
@smeschke
smeschke / multiview.py
Created September 4, 2020 04:26
Temporal video effect for Python/OpenCV
import cv2
import numpy as np
# Define the multiverse parameter
multiverse_parameter = 3
# Define the temporal seperation in frames
temporal_seperation = 24
# Define path to source video
@smeschke
smeschke / cnc_trace_path
Created September 23, 2019 18:21
Converts image to g-code
import cv2
import numpy as np
# Read in image
img = cv2.imread('/home/stephen/Desktop/test.png',0)
img = 255 - img
img = cv2.resize(img, (6000,6000))
h,w = img.shape
cutter_size = 20
buffer = int(cutter_size * 1.25)
@smeschke
smeschke / deep_cat.py
Last active April 16, 2023 23:11
Uses deep learning and the GrabCut algorithm to create pixel perfect semantic segmentation masks.
from mrcnn.config import Config
from mrcnn import model as modellib
from mrcnn import visualize
import cv2, os, numpy as np
# Make Model: https://github.com/matterport/Mask_RCNN/blob/master/samples/demo.ipynb
class Config(Config):
NAME = "deep_segment"
GPU_COUNT = 1
IMAGES_PER_GPU = 1
@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))
@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 / align_scan.py
Last active May 17, 2024 01:45
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 / 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