Skip to content

Instantly share code, notes, and snippets.

@roman-smirnov
Last active January 22, 2020 22:04
Show Gist options
  • Select an option

  • Save roman-smirnov/139dd8f970fc199434ff7fd6df4b770b to your computer and use it in GitHub Desktop.

Select an option

Save roman-smirnov/139dd8f970fc199434ff7fd6df4b770b to your computer and use it in GitHub Desktop.
AV Course Materials

Amit AV Course Materials

Base Input Image

road.jpg turn.jpg

Library Imports

import numpy as np
import matplotlib.pyplot as plt
import cv2
%matplotlib inline

Download Images

!wget -O road.jpg https://user-images.githubusercontent.com/11167081/72676198-699ac200-3a86-11ea-9c9b-12078fa3681b.jpg
!wget -O turn.jpg https://user-images.githubusercontent.com/11167081/72792252-9be82300-3c30-11ea-9d5a-3ae761cab497.jpg

Warp Transform

src = np.float32(
[[0,250], # bottom left
 [600, 250], # bottom right
 [295,8], # top left
 [380, 8]]) # top right

dst = np.float32(
[[100,279],
 [500, 279],
 [100,0],
 [500, 0]])

M = cv2.getPerspectiveTransform(src, dst)
warped = cv2.warpPerspective(img4.astype(np.uint8), M, (img4.shape[1], img4.shape[0]))

Histogram

hist = np.sum(warped, axis=0)
plt.plot(range(600),hist)

Lane Peaks

left = np.argmax(hist[:300])
print(left)
right = 300+np.argmax(hist[300:])
print(right)

Pipeline Function

def process_image(image):
  image= image[300:,600:1200,:]
  image= image[:,:,0]*0.3 + image[:,:,1]*0.6 + image[:,:,2]*0.1
  image= np.where(image>208, 255, 0)
  image = cv2.warpPerspective(image.astype(np.uint8), M, (image.shape[1], image.shape[0]))
  return image

Others

image = cv2.resize(image,(1920,580))
image = cv2.merge([image,image,image])
@roman-smirnov
Copy link
Author

road.jpg

@roman-smirnov
Copy link
Author

roman-smirnov commented Jan 21, 2020

turn.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment