Skip to content

Instantly share code, notes, and snippets.

View hackintoshrao's full-sized avatar
📚
Exploring AI agents on code search and understanding

Karthic Rao hackintoshrao

📚
Exploring AI agents on code search and understanding
View GitHub Profile
@hackintoshrao
hackintoshrao / warped.py
Created June 14, 2017 05:54
Region of interest and perspective transformation of the binary lane lines
import numpy as np
import cv2
import glob
import matplotlib.pyplot as plt
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((6*9,3), np.float32)
objp[:,:2] = np.mgrid[0:9, 0:6].T.reshape(-1,2)
# Arrays to store object points and image points from all the images.
@hackintoshrao
hackintoshrao / calibrate_undistort.py
Created June 10, 2017 02:30
calibrate the camera and undistort the image.
import numpy as np
import cv2
import glob
import matplotlib.pyplot as plt
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((6*9,3), np.float32)
objp[:,:2] = np.mgrid[0:9, 0:6].T.reshape(-1,2)
# Arrays to store object points and image points from all the images.
# Saturation color channel binary threshold.
def s_threshold(img, s_thresh=(0, 255)):
s_channel = cv2.cvtColor(img, cv2.COLOR_BGR2HLS)[:,:,2]
# Threshold color channel
s_binary = np.zeros_like(s_channel)
s_binary[(s_channel >= s_thresh[0]) & (s_channel <= s_thresh[1])] = 1
return s_binary
# Define a function that takes an image, gradient orientation,
@hackintoshrao
hackintoshrao / sobek_with_kernel.py
Created June 8, 2017 15:07
Sobel edge detection with kernel size and magnitude of x and y edge detection
# Define a function to return the magnitude of the gradient
# for a given sobel kernel size and threshold values
def mag_thresh(img, sobel_kernel=3, mag_thresh=(0, 255)):
# Convert to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
# 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)
# Calculate the gradient magnitude
gradmag = np.sqrt(sobelx**2 + sobely**2)
@hackintoshrao
hackintoshrao / sobel_detect.py
Created June 8, 2017 12:35
Edge detection using Sobels method and converting to binary image.
import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import pickle
# Read in an image and grayscale it
image = mpimg.imread('signs_vehicles_xygrad.png')
@hackintoshrao
hackintoshrao / chess_transform.py
Created June 8, 2017 11:04
undistort and perspective transform chess board image.
# Define a function that takes an image, number of x and y points,
# camera matrix and distortion coefficients
def corners_unwarp(img, nx, ny, mtx, dist):
# Use the OpenCV undistort() function to remove distortion
undist = cv2.undistort(img, mtx, dist, None, mtx)
# Convert undistorted image to grayscale
gray = cv2.cvtColor(undist, cv2.COLOR_BGR2GRAY)
# Search for corners in the grayscaled image
ret, corners = cv2.findChessboardCorners(gray, (nx, ny), None)
@hackintoshrao
hackintoshrao / simple_train.py
Created June 6, 2017 15:24
Training the model with a simple neural network to train a model given the image of the track.
import csv
import cv2
import numpy as np
# Data read from csv. CSV contains the image path and steerig angles recorded at various points of gameplay.
lines = []
csvPath = "/Users/hackintoshrao/Documents/code/self-drive/driving_log.csv"
with open(csvPath) as csvData:
# read from csv
@hackintoshrao
hackintoshrao / chess_board_corners.py
Created June 6, 2017 07:10
Usage of Open CV find and draw chess board corners, this is used in camera calibration.
import numpy as np
import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
# prepare object points
nx = 8# enter the number of inside corners in x
ny = 6# enter the number of inside corners in y
# Make a list of calibration images
@hackintoshrao
hackintoshrao / model.py
Last active June 6, 2017 13:07
Reading the image and the data
import csv
import cv2
import numpy as np
# Data read from csv. CSV contains the image path and steerig angles recorded at various points of gameplay.
lines = []
csvPath = "/Users/hackintoshrao/Documents/code/self-drive/driving_log.csv"
with open(csvPath) as csvData:
# read from csv
import (
"github.com/gorilla/mux"
"net/http/pprof"
"runtime/debug"
"runtime"
runtimepprof "runtime/pprof"
)
const (