Skip to content

Commit 5e89118

Browse files
dtection completed lines drawn
1 parent 41a2515 commit 5e89118

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

detector_opencv.py

+26-5
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,36 @@
77
print(image.shape)
88
height=image.shape[0]
99
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+
1122
def region_of_interst(img,vertices):
1223
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
1526
cv.fillPoly(mask,vertices,match_mask_color)
1627
mask_image=cv.bitwise_and(img,mask)
1728
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)
2041
plt.show()
2142

0 commit comments

Comments
 (0)