Skip to content

Instantly share code, notes, and snippets.

@pknowledge
Created August 22, 2019 20:14
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save pknowledge/86a148c6cd5f0f2820ba81561cc00a8e to your computer and use it in GitHub Desktop.
Save pknowledge/86a148c6cd5f0f2820ba81561cc00a8e to your computer and use it in GitHub Desktop.
Road Lane Line Detection with OpenCV
import matplotlib.pylab as plt
import cv2
import numpy as np
image = cv2.imread('road.jpg')
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
print(image.shape)
height = image.shape[0]
width = image.shape[1]
region_of_interest_vertices = [
(0, height),
(width/2, height/2),
(width, height)
]
def region_of_interest(img, vertices):
mask = np.zeros_like(img)
channel_count = img.shape[2]
match_mask_color = (255,) * channel_count
cv2.fillPoly(mask, vertices, match_mask_color)
masked_image = cv2.bitwise_and(img, mask)
return masked_image
cropped_image = region_of_interest(image,
np.array([region_of_interest_vertices], np.int32),)
plt.imshow(cropped_image)
plt.show()
@akshit7165
Copy link

You have to install the matplotlip lib using the pip command onto your cmd, if you have pip the just write pip install matplotlib. After this you'll be good to go, cheers!

@nthuls
Copy link

nthuls commented Jul 6, 2023

I need the link to the exact image
Please help

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