aboutsummaryrefslogtreecommitdiff
path: root/nicla/road.py
diff options
context:
space:
mode:
Diffstat (limited to 'nicla/road.py')
-rw-r--r--nicla/road.py31
1 files changed, 23 insertions, 8 deletions
diff --git a/nicla/road.py b/nicla/road.py
index 20863cc..1b06e78 100644
--- a/nicla/road.py
+++ b/nicla/road.py
@@ -1,11 +1,13 @@
import sensor, image, time, math
import uart
+import signs_detect
+import traffic_light
from consts import *
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.HVGA)
-sensor.skip_frames(time = 2000)
+sensor.skip_frames(time = 4000)
clock = time.clock()
WIDTH = 480
@@ -25,8 +27,7 @@ points = [(STRETCH, HORIZON),
(WIDTH-1+SQUEEZE, HEIGHT-1),
(-SQUEEZE, HEIGHT-1)]
-def main():
- img = sensor.snapshot()
+def drive(driveImg):
img.to_grayscale()
img.replace(vflip=True, hmirror=True)
img.rotation_corr(corners=points)
@@ -34,14 +35,12 @@ def main():
offset_sum = 0.0
offset_count = 0.0
-
for blob in img.find_blobs([(ROAD_MIN_BRIGHTNESS, 0xff)], pixels_threshold=100):
img.draw_rectangle(blob.rect())
area_weight = MIN_AREA + min(MAX_AREA, blob.w() * blob.h()) # limit max area_weight so small blobs still have impact
horizontal_pos = (blob.x() + blob.w()/2) / WIDTH
offset_sum += horizontal_pos * area_weight
offset_count += area_weight
-
# dit tegen niemand zeggen
if offset_count < 0.01: return
avg = offset_sum / offset_count
@@ -53,7 +52,23 @@ def main():
steerByte = int((avg + 1.0) * (DUI_CMD_STEER_END - DUI_CMD_STEER_START) / 2 + DUI_CMD_STEER_START)
uart.uart_buffer(steerByte)
+
+speed = signs_detect.init_kpts("speed")
+stop = signs_detect.init_kpts("stop")
+car = signs_detect.init_kpts("image")
while(True):
- main()
- uart.uart_buffer(DUI_CMD_SPEED_END)
- clock.tick()
+
+ img = sensor.snapshot()
+ data = traffic_light.traf_lights(img)
+ if data is not None:
+ uart.uart_buffer(data)
+
+
+ sign_img = sensor.snapshot()
+ data_sign = signs_detect.sign_detection(sign_img)
+ if data_sign is not None:
+ uart.uart_buffer(data_sign)
+
+ drive_img = sensor.snapshot()
+ drive(drive_img)
+ #uart.uart_buffer(DUI_CMD_SPEED_END)