Skip to content

Instantly share code, notes, and snippets.

View Seagor's full-sized avatar

Sean Gorman Seagor

View GitHub Profile
normalize = lambda x: (255 / (x.max() - x.min())) * (x - x.min())
smooth = lambda x: ndimage.convolve(x, np.ones([3,3])/9)
def threshold_mask(img, threshold=150):
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
mask = np.ones(gray.shape).astype(np.uint8)
mask[gray < threshold] = 0
return mask
def scanline_mask(imask):
import cv2
from skimage.morphology import binary_opening
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
%matplotlib inline
@Seagor
Seagor / twitter_public_streaming.py
Created May 5, 2016 19:06
Stream and Filter Tweets using the Twitter Public Streaming API
#!/bin/sh
"exec" "twxec" "-e" "filter_stream()" "$0" "$@"
import oauth2 as oauth
from trickle import twitter as tw
{{docstring "Make sure you have registered an application with Twitter in order to obtain your credentials. Once you have them, start streaming tweets using one of the filtering parameteres below"}}
app_key = {{string Twitter_App_Key}}
app_secret = {{string Twitter_App_Secret}}
import base64 as b64
import numpy as np
import cv2
import matplotlib.pyplot as plt
from ipywidgets import interact, interactive, fixed
from IPython.display import Image, display
import ipywidgets as widgets
from itertools import tee, izip
WINDOW_SIZE = 41 # size of window to use when computing averages. Endpoint images outside
@Seagor
Seagor / twitter_public_streaming.py
Created July 5, 2016 19:04
Stream and filter Tweets using the Twitter Public Streaming API
#!/bin/sh
"exec" "twxec" "-e" "filter_stream()" "$0" "$@"
import oauth2 as oauth
from trickle import twitter as tw
{{docstring "Make sure you have registered an application with Twitter in order to obtain your credentials. Once you have them, start streaming tweets using one of the filtering parameteres below"}}
app_key = {{string Twitter_App_Key}}
app_secret = {{string Twitter_App_Secret}}
import cv2
import numpy as np
%matplotlib inline
import matplotlib.pyplot as plt
def buffer_coastline(img, threshold=135):
arr = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
mask = np.ndarray(arr.shape + (3,)).astype(np.uint8)
below = arr < threshold
import pandas as pd
areas = []
for i, img in enumerate(found_objects):
for r, reg in enumerate(img):
for cnt in reg['contours']:
areas.append((cv2.contourArea(cnt), r, i))
df = pd.DataFrame(data = areas, columns=['area', 'dock', 'image'])