This file contains hidden or 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
""" | |
A simple example of an animated Brownian motion plot | |
By: David Rose | |
Date : 10/9/2017 | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation |
This file contains hidden or 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
""" | |
Video animation of stock ticker charts to represent randomness | |
By: David Rose | |
Date : 10/9/2017 | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
from itertools import cycle |
This file contains hidden or 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
""" | |
Plot out grid of 5x5 brownian motion 2D plots | |
By: David Rose | |
Date : 10/9/2017 | |
""" | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import pandas as pd | |
import random |
This file contains hidden or 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
""" | |
Video animation of Monte Carlo estimation of a circle's area. | |
The function (x**2 + y**2 + r**2) can be changed around to create other shapes of choice. | |
By: David Rose | |
Date : 10/9/2017 | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation |
This file contains hidden or 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 toCalibrate(img,nx,ny): | |
objpoints = [] | |
imgpoints = [] | |
objp = np.zeros((nx*ny, 3), np.float32) | |
objp[:,:2] = np.mgrid[0:nx,0:ny].T.reshape(-1,2) # x,y coordinates | |
# Find chessboard corners | |
ret, corners= cv2.findChessboardCorners(img, (nx,ny), None) | |
# If found, draw corners |
This file contains hidden or 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 toWarp(img,src,dst): | |
# Grab the image shape | |
if len(np.shape(img)) > 2: | |
img_size = (toGray(img).shape[1], toGray(img).shape[0]) | |
else: | |
img_size = (img.shape[1], img.shape[0]) | |
#im2 = img.reshape(img.shape[0], img.shape[1]) | |
plt.suptitle('Before Warped', fontsize=14, fontweight='bold') |
This file contains hidden or 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
# for a given sobel kernel size and threshold values | |
def toMagSobel(img, sobel_kernel=3, mag_thresh=(0, 255)): | |
# Convert to grayscale | |
if len(np.shape(img)) > 2: | |
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) | |
else: | |
gray = img | |
# Take both Sobel x and y gradients | |
sobelx = cv2.Sobel(gray, cv2.CV_64F, 1, 0, ksize=sobel_kernel) | |
sobely = cv2.Sobel(gray, cv2.CV_64F, 0, 1, ksize=sobel_kernel) |
This file contains hidden or 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
plt.suptitle('After Sobel Binary', fontsize=14, fontweight='bold') | |
plt.imshow(step2) | |
plt.show() | |
histogram = np.sum(step2[step2.shape[0]//2:,:], axis=0) | |
plt.suptitle('Histogram of Pixels', fontsize=14, fontweight='bold') | |
plt.plot(histogram) | |
plt.show() |
This file contains hidden or 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 regressionLanesTracker(src): | |
binary_warped = src | |
# Assuming you have created a warped binary image called "binary_warped" | |
# Take a histogram of the bottom half of the image | |
histogram = np.sum(binary_warped[int(binary_warped.shape[0]/2):,:], axis=0) | |
# Create an output image to draw on and visualize the result | |
out_img = np.dstack((binary_warped, binary_warped, binary_warped))*255 | |
# Find the peak of the left and right halves of the histogram | |
# These will be the starting point for the left and right lines |
This file contains hidden or 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
""" | |
Add polygon and Overlay and Warp | |
""" | |
def polygonOverlay(src): | |
binary_warped = src | |
# Create an image to draw the lines on | |
warp_zero = np.zeros_like(binary_warped).astype(np.uint8) | |
color_warp = np.dstack((warp_zero, warp_zero, warp_zero)) |
OlderNewer