-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode
90 lines (75 loc) · 2.56 KB
/
code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import matplotlib. pylab as plt
import cv2
import numpy as np
import time
def region_of_interest(img, vertices):
mask=np.zeros_like(img)
#channel_count =img.shape[2]
if len(img.shape) > 2:
channel_count = img.shape[2]
ignore_mask_color = (255,) * channel_count
else:
ignore_mask_color = 255
cv2.fillPoly(mask, vertices, ignore_mask_color)
masked_image=cv2.bitwise_and(img, mask)
return masked_image
def drow_the_line(image, lines):
image=np.copy(image)
line_image= np.zeros((image.shape[0],image.shape[1],3),dtype=np.uint8)
if lines is None:
print()
else:
for line in lines:
for x1, y1, x2, y2 in line:
cv2.line(line_image,(x1,y1),(x2,y2),(255,115,200), thickness=15)
image= cv2.addWeighted(image,0.8, line_image,1,0.0)
return image
#image=cv2.imread('road.jpg')
#image=cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
def process(image):
a=True
while (a):
if image is None:
a=False
break
else:
print(image.shape)
hight =image.shape[0]
width =image.shape[1]
#reagion of interset
imshape=image.shape
region_of_interest_vertices = np.array([[ (-300, imshape[0]),
(450, 400),
(950, 400),
(1500, 875)]],
dtype=np.int32)
blur_image=cv2.GaussianBlur(image,(5,5),15)
grar_image = cv2.cvtColor(blur_image,cv2.COLOR_RGB2GRAY)
canny_image= cv2.Canny(grar_image, 100, 200)
cropped_image = region_of_interest(canny_image,
np.array([region_of_interest_vertices],np.int32))
lines=cv2.HoughLinesP(cropped_image,
rho=6,
theta=np.pi/180,
threshold=20,
minLineLength=150,
maxLineGap=50)
image_with_lines= drow_the_line(image,lines)
return image_with_lines
capvid=cv2.VideoCapture('test 1.mp4')
while(capvid.isOpened()):
ret, frames =capvid.read()
time.sleep(0.01)
frames = process(frames)
if frames is None:
print("end")
break
else:
cv2.imshow('frames', frames)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
capvid .release()
cv2.destroyAllWindows()
#image_with_line = drow_the_line(image, lines)
#plt.imshow(image_with_line)
#plt.show()