aboutsummaryrefslogtreecommitdiff
path: root/nicla/traffic_light.py
diff options
context:
space:
mode:
Diffstat (limited to 'nicla/traffic_light.py')
-rw-r--r--nicla/traffic_light.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/nicla/traffic_light.py b/nicla/traffic_light.py
index 3d81139..9499aea 100644
--- a/nicla/traffic_light.py
+++ b/nicla/traffic_light.py
@@ -30,12 +30,9 @@ def rgb2hsv(rgb):
h = (h/6.0) % 1.0
return (h, s, v)
-while(True):
- clock.tick()
- img = sensor.snapshot()
- ## todo: downsample img
- original = img.copy(copy_to_fb=True)
- img = img.to_grayscale()
+
+def traf_lights(imgTraffic):
+ img = imgTraffic.to_grayscale()
for blob in img.find_blobs([(0, 60)], pixels_threshold=100):
aspect = blob.h() / blob.w()
if abs(aspect - 2.2) > 0.5: continue
@@ -55,11 +52,20 @@ while(True):
if i == 1 and abs(h - 0.05) > 0.1: continue
if i == 2 and abs(h - 0.40) > 0.1: continue
light_status = i + 1
- print((h,s,v,))
+ #print((h,s,v,))
break
if light_status == 0:
continue
img.draw_rectangle(blob.rect())
img.draw_circle(lights[light_status-1][0], lights[light_status-1][1], 2)
- print(("", "rood", "geel", "groen")[light_status])
+ #print(("", "rood", "geel", "groen")[light_status])
+
+ if light_status == 1:
+ return 0x06
+ elif light_status == 2:
+ return 0x07
+ elif light_status == 3:
+ return 0x08
+ else:
+ return 0x01