Update rc_driver.py
Add threshold checking to determine if traffic light is on
Esse commit está contido em:
+19
-13
@@ -77,6 +77,9 @@ class ObjectDetection(object):
|
||||
# y camera coordinate of the target point 'P'
|
||||
v = 0
|
||||
|
||||
# minimum value to proceed traffic light state validation
|
||||
threshold = 150
|
||||
|
||||
# detection
|
||||
cascade_obj = cascade_classifier.detectMultiScale(
|
||||
gray_image,
|
||||
@@ -101,22 +104,25 @@ class ObjectDetection(object):
|
||||
roi = gray_image[y_pos+10:y_pos + height-10, x_pos+10:x_pos + width-10]
|
||||
mask = cv2.GaussianBlur(roi, (25, 25), 0)
|
||||
(minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(mask)
|
||||
cv2.circle(roi, maxLoc, 5, (255, 0, 0), 2)
|
||||
|
||||
# Red light
|
||||
if 1.0/8*(height-30) < maxLoc[1] < 4.0/8*(height-30):
|
||||
cv2.putText(image, 'Red', (x_pos+5, y_pos-5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
|
||||
self.red_light = True
|
||||
# check if light is on
|
||||
if maxVal - minVal > threshold:
|
||||
cv2.circle(roi, maxLoc, 5, (255, 0, 0), 2)
|
||||
|
||||
# Green light
|
||||
elif 5.5/8*(height-30) < maxLoc[1] < height-30:
|
||||
cv2.putText(image, 'Green', (x_pos+5, y_pos - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
|
||||
self.green_light = True
|
||||
# Red light
|
||||
if 1.0/8*(height-30) < maxLoc[1] < 4.0/8*(height-30):
|
||||
cv2.putText(image, 'Red', (x_pos+5, y_pos-5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)
|
||||
self.red_light = True
|
||||
|
||||
# yellow light
|
||||
#elif 4.0/8*(height-30) < maxLoc[1] < 5.5/8*(height-30):
|
||||
# cv2.putText(image, 'Yellow', (x_pos+5, y_pos - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255), 2)
|
||||
# self.yellow_light = True
|
||||
# Green light
|
||||
elif 5.5/8*(height-30) < maxLoc[1] < height-30:
|
||||
cv2.putText(image, 'Green', (x_pos+5, y_pos - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
|
||||
self.green_light = True
|
||||
|
||||
# yellow light
|
||||
#elif 4.0/8*(height-30) < maxLoc[1] < 5.5/8*(height-30):
|
||||
# cv2.putText(image, 'Yellow', (x_pos+5, y_pos - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 255), 2)
|
||||
# self.yellow_light = True
|
||||
return v
|
||||
|
||||
|
||||
|
||||
Referência em uma Nova Issue
Bloquear um usuário