|
7 | 7 | print(image.shape)
|
8 | 8 | height=image.shape[0]
|
9 | 9 | width=image.shape[1]
|
10 |
| -region_of_interst_vertices=[(0,height),(width/2,height/2),(width,height)] |
| 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 | + |
11 | 22 | def region_of_interst(img,vertices):
|
12 | 23 | mask=np.zeros_like(img)
|
13 |
| - channel_count=img.shape[2] |
14 |
| - match_mask_color=(255,)*channel_count |
| 24 | + #channel_count=img.shape[2] |
| 25 | + match_mask_color=255 |
15 | 26 | cv.fillPoly(mask,vertices,match_mask_color)
|
16 | 27 | mask_image=cv.bitwise_and(img,mask)
|
17 | 28 | return mask_image
|
18 |
| -cropped=region_of_interst(image,np.array([region_of_interst_vertices],np.int32)) |
19 |
| -plt.imshow(cropped) |
| 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) |
20 | 41 | plt.show()
|
21 | 42 |
|
0 commit comments