forked from karauri14/safetyplus-pi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaneOver.py
41 lines (29 loc) · 1.19 KB
/
laneOver.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
import cv2
import numpy as np
# Define range of color in HSV yellow
lower_color = np.array([10, 30, 180])
upper_color = np.array([20, 255, 255])
count = {'LANE':0}
MAX_COUNT = 9
MIN_AREA = 2.5
MAX_AREA = 30
FRAME_CUT = 35
def isNotOver(frame):
frame = frame[int(frame.shape[0] / 2):,int(frame.shape[1] / 2)+FRAME_CUT:]
#resize_frame = cv2.rectangle(frame, (0,0), (int(frame.shape[1]/2)+15, int(frame.shape[0])), (0,0,0), thickness=-1)
#resize_frame = cv2.rectangle(resize_frame, (int(resize_frame.shape[1]/2), 0), (int(resize_frame.shape[1]), int(resize_frame.shape[0]/2)), (0,0,0), thickness=-1)
# Convert BGR to HSV
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
# Threshold the HSV image to get only yellow colors
img_mask = cv2.inRange(hsv, lower_color, upper_color)
#cv2.imshow('yellow', img_mask)
image, contours, hierarchy = cv2.findContours(img_mask.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
area = cv2.contourArea(cnt)
if area < MIN_AREA or MAX_AREA < area:
continue
count['LANE'] += 1
if count['LANE'] >= MAX_COUNT:
count['LANE'] = 0
return True
return False