-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathdetection.py
79 lines (55 loc) · 1.73 KB
/
detection.py
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
#!/usr/bin/python
import numpy as np
import random as rnd
import cv2
from utils import *
from make_model import *
seed = 11
rnd.seed(seed)
np.random.seed(seed)
############################
#### EDIT ONLY THIS BLOCK
videofile = './test_video.mp4'
cap = cv2.VideoCapture(videofile)
model = make_model()
model.load_weights('weights_best.h5')
lower = [0, 0, 0]
upper = [100, 100, 100]
stepSize = 30
############################
lower = np.array(lower)
upper = np.array(upper)
while(True):
ret,frame = cap.read()
if(ret == False):
print("Done")
break
############################
#### EDIT ONLY THIS BLOCK
#Convert image to HSV from BGR
img_hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# Find the pixels that correspond to road
img_out = cv2.inRange(img_hsv, lower, upper)
############################
# Clean from noisy pixels and keep only the largest connected segment
img_out = post_process(img_out)
image_masked = frame.copy()
# Get masked image
image_masked[img_out == 0] = (0, 0, 0)
s=0.25
#Resize images for computational efficiency
frame = cv2.resize(frame,None, fx=s,fy=s)
image_masked = cv2.resize(image_masked,None, fx=s,fy=s)
#Run the sliding window detection process
bbox_list, totalWindows, correct, score = detectionProcess(cv2.cvtColor(frame,cv2.COLOR_BGR2RGB), model, winH=50, winW=50, depth=3, nb_images=1, scale=1, stepSize=stepSize, thres_score=0.05)
#Draw the detections
drawBoxes(frame, bbox_list)
# Draw detections and road masks
cv2.imshow('video',sidebyside(frame,image_masked))
k = cv2.waitKey(3)
#QUIT
if(k & 0xFF == ord('q')):
cv2.destroyWindow("video")
break
cap.release()
cv2.destroyAllWindows()