
import numpy as np
import matplotlib.pyplot as plt
import cv2
%matplotlib inline
!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
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]))
hist = np.sum(warped, axis=0)
plt.plot(range(600),hist)
left = np.argmax(hist[:300])
print(left)
right = 300+np.argmax(hist[300:])
print(right)
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
image = cv2.resize(image,(1920,580))
image = cv2.merge([image,image,image])