Skip to content

Commit a1bc753

Browse files
Create Lane-detect.py
1 parent 4a44248 commit a1bc753

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Lane-detect.py

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import matplotlib.pylab as plt
2+
import cv2 as cv
3+
import numpy as np
4+
image=cv.imread('lane.jpeg')
5+
image=cv.cvtColor(image,cv.COLOR_BGR2RGB)
6+
7+
#print(image.shape)
8+
height=image.shape[0]
9+
width=image.shape[1]
10+
11+
def draw_the_line(img,lines):
12+
img=np.copy(img)
13+
blank_image=np.zeros((img.shape[0],img.shape[1],3),dtype=np.uint8)
14+
15+
for line in lines:
16+
for x1,y1,x2,y2 in line:
17+
cv.line(blank_image,(x1,y1),(x2,y2),(255,255,0),thickness=2)
18+
img=cv.addWeighted(img,0.8,blank_image,1,0.0)
19+
return img
20+
21+
22+
def region_of_interst(img,vertices):
23+
mask=np.zeros_like(img)
24+
#channel_count=img.shape[2]
25+
match_mask_color=255
26+
cv.fillPoly(mask,vertices,match_mask_color)
27+
mask_image=cv.bitwise_and(img,mask)
28+
return mask_image
29+
30+
31+
region_of_interst_vertices=[(0,height),(width/2,height/2),(width,height)]
32+
gray=cv.cvtColor(image,cv.COLOR_BGR2GRAY)
33+
canny=cv.Canny(gray,100,200)
34+
35+
cropped=region_of_interst(canny,np.array([region_of_interst_vertices],np.int32))
36+
line1=cv.HoughLinesP(cropped,rho=6,theta=np.pi/60,threshold=160,lines=np.array([]),minLineLength=40,maxLineGap=20)
37+
38+
39+
image_width_line=draw_the_line(image,line1)
40+
plt.imshow(image_width_line)
41+
plt.show()

0 commit comments

Comments
 (0)