aboutsummaryrefslogtreecommitdiff
path: root/nicla
diff options
context:
space:
mode:
Diffstat (limited to 'nicla')
-rw-r--r--nicla/consts.py6
-rw-r--r--nicla/downscale.py19
-rw-r--r--nicla/end.jpgbin0 -> 10829 bytes
-rw-r--r--nicla/image.jpgbin0 -> 30111 bytes
-rw-r--r--nicla/no_entry.jpgbin0 -> 16864 bytes
-rw-r--r--nicla/road.py73
-rw-r--r--nicla/speed.jpgbin0 -> 27055 bytes
-rw-r--r--nicla/stop.jpgbin0 -> 35442 bytes
-rw-r--r--nicla/traffic_light.py22
-rw-r--r--nicla/uart.py (renamed from nicla/serial_test.py)5
10 files changed, 115 insertions, 10 deletions
diff --git a/nicla/consts.py b/nicla/consts.py
new file mode 100644
index 0000000..b5ccd9a
--- /dev/null
+++ b/nicla/consts.py
@@ -0,0 +1,6 @@
+DUI_CMD_SIGN_START = 0x01
+DUI_CMD_SIGN_END = 0x0f
+DUI_CMD_SPEED_START = 0x10
+DUI_CMD_SPEED_END = 0x1f
+DUI_CMD_STEER_START = 0x20
+DUI_CMD_STEER_END = 0xff
diff --git a/nicla/downscale.py b/nicla/downscale.py
new file mode 100644
index 0000000..738b4bb
--- /dev/null
+++ b/nicla/downscale.py
@@ -0,0 +1,19 @@
+import sensor, image, time, math
+
+sensor.reset()
+sensor.set_pixformat(sensor.RGB565)
+sensor.set_framesize(sensor.HVGA)
+sensor.skip_frames(time = 2000)
+sensor.set_vflip(True)
+sensor.set_hmirror(True)
+clock = time.clock()
+
+def main():
+ img = sensor.snapshot()
+ img.to_grayscale()
+ img.scale(copy_to_fb=True, x_size=100)
+
+if __name__ == "__main__":
+ while(True):
+ main()
+ clock.tick()
diff --git a/nicla/end.jpg b/nicla/end.jpg
new file mode 100644
index 0000000..7756273
--- /dev/null
+++ b/nicla/end.jpg
Binary files differ
diff --git a/nicla/image.jpg b/nicla/image.jpg
new file mode 100644
index 0000000..51a3c75
--- /dev/null
+++ b/nicla/image.jpg
Binary files differ
diff --git a/nicla/no_entry.jpg b/nicla/no_entry.jpg
new file mode 100644
index 0000000..6b1c54b
--- /dev/null
+++ b/nicla/no_entry.jpg
Binary files differ
diff --git a/nicla/road.py b/nicla/road.py
new file mode 100644
index 0000000..143a9c5
--- /dev/null
+++ b/nicla/road.py
@@ -0,0 +1,73 @@
+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 = 4000)
+clock = time.clock()
+
+WIDTH = 480
+HEIGHT = 320
+MAX_AREA = WIDTH * HEIGHT / 10
+MIN_AREA = 40
+
+HORIZON = 150
+STRETCH = 40
+SQUEEZE = 400
+
+STEERING_ENTHOUSIASM = 3.0
+ROAD_MIN_BRIGHTNESS = 0xa0
+
+points = [(STRETCH, HORIZON),
+ (WIDTH-1-STRETCH, HORIZON),
+ (WIDTH-1+SQUEEZE, HEIGHT-1),
+ (-SQUEEZE, HEIGHT-1)]
+
+
+def drive(img):
+ img.to_grayscale()
+ img.replace(vflip=True, hmirror=True)
+ img.rotation_corr(corners=points)
+ img.gaussian(3)
+
+ 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
+ avg = avg * 2 - 1
+ avg *= STEERING_ENTHOUSIASM
+ avg = max(-1, min(1, avg))
+
+ steerByte = int((avg + 1.0) * (DUI_CMD_STEER_END - DUI_CMD_STEER_START) / 2 + DUI_CMD_STEER_START)
+
+ uart.uart_buffer(steerByte)
+
+
+
+while(True):
+
+ #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(0x1f)
diff --git a/nicla/speed.jpg b/nicla/speed.jpg
new file mode 100644
index 0000000..c6cf7a9
--- /dev/null
+++ b/nicla/speed.jpg
Binary files differ
diff --git a/nicla/stop.jpg b/nicla/stop.jpg
new file mode 100644
index 0000000..cd35e95
--- /dev/null
+++ b/nicla/stop.jpg
Binary files differ
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
diff --git a/nicla/serial_test.py b/nicla/uart.py
index 276f6d1..da150b0 100644
--- a/nicla/serial_test.py
+++ b/nicla/uart.py
@@ -16,14 +16,15 @@ def uart_send(byte):
__uart_buffer = bytearray()
def uart_flush():
global __uart_buffer
- print("UART FLUSH START")
+ # print("UART FLUSH START")
for byte in __uart_buffer:
- print(f"BYTE 0x{byte:02X}")
+ # print(f"BYTE 0x{byte:02X}")
uart_send(byte) # dit is de oplossing
udelay(2000)
uart_send(byte)
udelay(2000)
uart_send(byte)
+ udelay(2000)
__uart_buffer = bytearray()
def tx_irq_handler(pin):