This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy.fft import fft, ifft, fft2, ifft2, fftshift | |
import numpy as np | |
def fft_convolve2d(x,y): | |
""" 2D convolution, using FFT""" | |
fr = fft2(x) | |
fr2 = fft2(np.flipud(np.fliplr(y))) | |
m,n = fr.shape | |
cc = np.real(ifft2(fr*fr2)) | |
cc = np.roll(cc, -m/2+1,axis=0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
def low_rank_approx(SVD=None, A=None, r=1): | |
""" | |
Computes an r-rank approximation of a matrix | |
given the component u, s, and v of it's SVD | |
Requires: numpy | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pickle | |
import gzip | |
def save(object, filename, protocol = 0): | |
"""Saves a compressed object to disk | |
""" | |
file = gzip.GzipFile(filename, 'wb') | |
file.write(pickle.dumps(object, protocol)) | |
file.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pprocess | |
import time | |
import numpy as np | |
# Define a function to parallelize: | |
def takeuptime(x): | |
"""A function to waste CPU cycles""" | |
time.sleep(0.1) | |
return x[-1] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def adjust(t, og): | |
t2 = 1.34722124e-4 * t | |
t3 = 2.04052596e-6 * t ** 2 | |
t4 = 2.32820948e-9 * t ** 3 | |
sgcf = 1.00130346 - t2 + t3 - t4 | |
sg = og * sgcf | |
adjusted_og = sg | |
OE = -668.962 + 1262.45 * sg - 776.43 * sg * sg + 182.94 * sg * sg * sg | |
abv_max = (sg - 1) * 105 * 1.25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import time | |
class bandProcess(object): | |
""" | |
Component to isolate specific frequency bands | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib | |
import re | |
import time | |
import datetime | |
def get_ip(): | |
group = re.compile(u'(?P<ip>\d+\.\d+\.\d+\.\d+)').search( | |
urllib.URLopener().open('http://jsonip.com/').read()).groupdict() | |
return group['ip'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import time | |
import urllib2 | |
import cv2 | |
import numpy as np | |
""" | |
Examples of objects for image frame aquisition from both IP and |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
# Create object to read images from camera 0 | |
cam = cv2.VideoCapture(1) | |
class imgSlice(object): | |
def __init__(self): | |
self.x = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import Image | |
import ImageGrab | |
while True: | |
time.sleep(0.5) | |
t = str(time.time()).replace('.','-') | |
tt = time.time() | |
img=ImageGrab.grab() | |
img = img.resize((800,600)) |
OlderNewer