Skip to content

Commit

Permalink
Update rc_driver.py
Browse files Browse the repository at this point in the history
Add threshold checking to determine if traffic light is on
  • Loading branch information
hamuchiwa committed Aug 18, 2015
1 parent d8d0397 commit d324fe2
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions computer/rc_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def detect(self, cascade_classifier, gray_image, image):
# 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,
Expand All @@ -101,22 +104,25 @@ def detect(self, cascade_classifier, gray_image, image):
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

# 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
# check if light is on
if maxVal - minVal > threshold:
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

# 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


Expand Down Expand Up @@ -282,4 +288,4 @@ def server_thread2(host, port):
video_thread.start()

if __name__ == '__main__':
ThreadServer()
ThreadServer()

0 comments on commit d324fe2

Please sign in to comment.