Skip to content

Instantly share code, notes, and snippets.

View mitkrieg's full-sized avatar

Mitchell Krieger mitkrieg

View GitHub Profile
@mitkrieg
mitkrieg / setup_for_faces.py
Last active October 27, 2020 04:44
set up for finding faces in an image
import cv2
import numpy as np
#path to classifiers
path = '/Users/mitchellkrieger/opt/anaconda3/envs/learn-env/share/opencv4/haarcascades/'
#get image classifiers
face_cascade = cv2.CascadeClassifier(path +'haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier(path +'haarcascade_eye.xml')
@mitkrieg
mitkrieg / find_a_face.py
Last active October 30, 2020 20:34
Find a face in an image
#read image
img = cv2.imread('people.jpg')
#convert to gray
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#detect faces
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
#for each face
@mitkrieg
mitkrieg / add_a_witch.py
Last active October 28, 2020 14:43
part 1/2 for placing witch hats on faces in an image
import cv2
import numpy as np
path = '/Users/YOUR/PATH/HERE/share/opencv4/haarcascades/'
#get facial classifiers
face_cascade = cv2.CascadeClassifier(path +'haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier(path +'haarcascade_eye.xml')
#read images
@mitkrieg
mitkrieg / place_witch_hat.py
Last active October 27, 2020 04:43
part 2/2 for placing witch hats on faces in an image
for (x,y,w,h) in faces:
#retangle for testing purposes
#img = cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
#coordinates of face region
face_w = w
face_h = h
face_x1 = x
face_x2 = face_x1 + face_w
face_y1 = y
@mitkrieg
mitkrieg / witch_on_video.py
Last active October 27, 2020 04:57
takes in live video and returns video feed with a facial recognition filter
import cv2
import numpy as np
path = '/Users/YOUR/PATH/HERE/share/opencv4/haarcascades/'
#get facial classifiers
face_cascade = cv2.CascadeClassifier(path +'haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier(path +'haarcascade_eye.xml')
#read images
@mitkrieg
mitkrieg / read_covid_data.py
Last active July 26, 2022 21:07
read_covid_data
import pandas as pd
# read data from NY times
df = pd.read_csv("https://raw.githubusercontent.com/nytimes/covid-19-data/master/us.csv")
# engineer new cases
df['new_cases'] = df.cases - df.cases.shift().fillna(0)
# create pandas time series
df.date = pd.to_datetime(df.date)
@mitkrieg
mitkrieg / basic_fbprophet.py
Created February 19, 2021 23:32
Basic FB Prophet Model
from fbprophet import Prophet
# instantiate the model and fit the timeseries
prophet = Prophet()
prophet.fit(ts)
# create a future data frame
future = prophet.make_future_dataframe(periods=25)
forecast = prophet.predict(future)
from fbprophet.plot import add_changepoints_to_plot
a = add_changepoints_to_plot(fig.gca(),m,forcast)
fig
# instantiate the model and fit the timeseries
prophet = Prophet(weekly_seasonality=False, changepoint_range=1,changepoint_prior_scale=0.75)
prophet.fit(ts)
# create a future data frame
future = prophet.make_future_dataframe(periods=25)
forecast = prophet.predict(future)
# display the most critical output columns from the forecast
forecast[['ds','yhat','yhat_lower','yhat_upper']].head()
@mitkrieg
mitkrieg / app.py
Last active February 26, 2021 21:18
Dash app.py
import dash
import dash_bootstrap_components as dbc
#Instantiates the Dash app and identify the server
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server