diff options
| author | lonkaars <loek@pipeframe.xyz> | 2023-06-08 09:33:12 +0200 | 
|---|---|---|
| committer | lonkaars <loek@pipeframe.xyz> | 2023-06-08 09:33:12 +0200 | 
| commit | c81c6223b7d9e5973f5d2825c399d5777e093c58 (patch) | |
| tree | a7eceaf2e0b6525f6aeacaedb1b33e42582529e8 /nicla/traffic_light.py | |
| parent | 97939ee4eaad5937a0a2eee190b2b9028d009a97 (diff) | |
| parent | 2903e61cbe2eeff3121f67da516ea195999f0bba (diff) | |
merge dev into master
Diffstat (limited to 'nicla/traffic_light.py')
| -rw-r--r-- | nicla/traffic_light.py | 22 | 
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  |