aboutsummaryrefslogtreecommitdiff
path: root/nicla
diff options
context:
space:
mode:
Diffstat (limited to 'nicla')
-rw-r--r--nicla/.Trashes/._501bin0 -> 4096 bytes
-rw-r--r--nicla/.Trashes/501/._image.pngbin0 -> 4096 bytes
-rw-r--r--nicla/.Trashes/501/._temp.mjpeg0
-rw-r--r--nicla/.Trashes/501/image.pngbin0 -> 20357 bytes
-rw-r--r--nicla/.Trashes/501/temp.mjpegbin0 -> 4096 bytes
-rw-r--r--nicla/._end.jpgbin0 -> 4096 bytes
-rw-r--r--nicla/._image.jpgbin0 -> 4096 bytes
-rw-r--r--nicla/._no_entry.jpgbin0 -> 4096 bytes
-rw-r--r--nicla/._speed.jpgbin0 -> 4096 bytes
-rw-r--r--nicla/._stop.jpgbin0 -> 4096 bytes
-rw-r--r--nicla/._temp.orbbin0 -> 4096 bytes
-rw-r--r--nicla/.fseventsd/fseventsd-uuid1
-rw-r--r--nicla/ERROR.LOG1
-rw-r--r--nicla/README.txt17
-rw-r--r--nicla/end.jpgbin0 -> 10829 bytes
-rw-r--r--nicla/image.jpgbin0 -> 30111 bytes
-rw-r--r--nicla/kpts.orbbin0 -> 2696 bytes
-rw-r--r--nicla/no_entry.jpgbin0 -> 16864 bytes
-rw-r--r--nicla/road.py31
-rw-r--r--nicla/signs_detect.py61
-rw-r--r--nicla/speed.jpgbin0 -> 27055 bytes
-rw-r--r--nicla/speed.orbbin0 -> 4096 bytes
-rw-r--r--nicla/stop.jpgbin0 -> 35442 bytes
-rw-r--r--nicla/temp.orbbin0 -> 6308 bytes
-rw-r--r--nicla/traffic_light.py22
25 files changed, 117 insertions, 16 deletions
diff --git a/nicla/.Trashes/._501 b/nicla/.Trashes/._501
new file mode 100644
index 0000000..338bd7b
--- /dev/null
+++ b/nicla/.Trashes/._501
Binary files differ
diff --git a/nicla/.Trashes/501/._image.png b/nicla/.Trashes/501/._image.png
new file mode 100644
index 0000000..02cf786
--- /dev/null
+++ b/nicla/.Trashes/501/._image.png
Binary files differ
diff --git a/nicla/.Trashes/501/._temp.mjpeg b/nicla/.Trashes/501/._temp.mjpeg
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/nicla/.Trashes/501/._temp.mjpeg
diff --git a/nicla/.Trashes/501/image.png b/nicla/.Trashes/501/image.png
new file mode 100644
index 0000000..d8bc7f5
--- /dev/null
+++ b/nicla/.Trashes/501/image.png
Binary files differ
diff --git a/nicla/.Trashes/501/temp.mjpeg b/nicla/.Trashes/501/temp.mjpeg
new file mode 100644
index 0000000..577a50a
--- /dev/null
+++ b/nicla/.Trashes/501/temp.mjpeg
Binary files differ
diff --git a/nicla/._end.jpg b/nicla/._end.jpg
new file mode 100644
index 0000000..c26df8c
--- /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..4520888
--- /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..a22af57
--- /dev/null
+++ b/nicla/._no_entry.jpg
Binary files differ
diff --git a/nicla/._speed.jpg b/nicla/._speed.jpg
new file mode 100644
index 0000000..f3a3faf
--- /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..4a47a5b
--- /dev/null
+++ b/nicla/._stop.jpg
Binary files differ
diff --git a/nicla/._temp.orb b/nicla/._temp.orb
new file mode 100644
index 0000000..acfd770
--- /dev/null
+++ b/nicla/._temp.orb
Binary files differ
diff --git a/nicla/.fseventsd/fseventsd-uuid b/nicla/.fseventsd/fseventsd-uuid
new file mode 100644
index 0000000..d3c0376
--- /dev/null
+++ b/nicla/.fseventsd/fseventsd-uuid
@@ -0,0 +1 @@
+6FDC5716-0B86-4159-ACC7-80164FCE6FE6 \ No newline at end of file
diff --git a/nicla/ERROR.LOG b/nicla/ERROR.LOG
new file mode 100644
index 0000000..ba1a6e3
--- /dev/null
+++ b/nicla/ERROR.LOG
@@ -0,0 +1 @@
+FATAL ERROR:
diff --git a/nicla/README.txt b/nicla/README.txt
new file mode 100644
index 0000000..9fdd185
--- /dev/null
+++ b/nicla/README.txt
@@ -0,0 +1,17 @@
+Thank you for supporting Arduino and the OpenMV project!
+
+To download the OpenMV IDE, please visit:
+https://openmv.io/pages/download
+
+For tutorials and documentation, please visit:
+https://docs.arduino.cc/
+http://docs.openmv.io/
+
+For technical OpenMV support and projects, please visit the forums:
+http://forums.openmv.io/
+
+For Arduino related issues, please visit the Arduino help center:
+https://support.arduino.cc/
+
+Please use Github to report bugs and issues:
+https://github.com/openmv/openmv
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/kpts.orb b/nicla/kpts.orb
new file mode 100644
index 0000000..0c3e1e7
--- /dev/null
+++ b/nicla/kpts.orb
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
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)
diff --git a/nicla/signs_detect.py b/nicla/signs_detect.py
new file mode 100644
index 0000000..786972d
--- /dev/null
+++ b/nicla/signs_detect.py
@@ -0,0 +1,61 @@
+import sensor, image
+
+kpts_threshold = 20
+kpts_corner = image.CORNER_FAST
+
+def init_kpts(str):
+ temp_img = image.Image(f"./{str}.jpg",copy_to_fb=True)
+ temp_img.to_grayscale()
+ kpts = temp_img.find_keypoints(max_keypoints=128, threshold=kpts_threshold, corner_detector=kpts_corner, scale_factor=1.2)
+ return kpts
+
+def match_kpts(kpts0, kpts1):
+ if kpts0 is not None and kpts1 is not None:
+ match = image.match_descriptor(kpts0, kpts1, threshold=70)
+ #print("matched:%d dt:%d"%(match.count(), match.theta()))
+ if match.count() > 0:
+ print(match.count())
+ return match.count() > 1
+ else:
+ return 0
+
+def read_red_sign(val, img, kpts):
+ if match_kpts(kpts, stop):
+ img.draw_rectangle(val.rect())
+ #img.draw_cross(match.cx(), match.cy(), size=10)
+ #print("stop")
+ return 0x01
+ if match_kpts(kpts, speed):
+ img.draw_rectangle(val.rect())
+ #print("speed")
+ return 0x02
+ if match_kpts(kpts, car):
+ img.draw_rectangle(val.rect())
+ #print("car")
+ return 0x03
+
+#def read_red_sign(val, img, kpts):
+
+def sign_detection(img):
+ ######## Detect signs
+ blobs_r = img.find_blobs([(0, 100, 25, 63, -128, 127)])
+ blobs_b = img.find_blobs([(0, 29, 11, -128, -31, -5)])
+ #print(f"old: { len(blobs_r) + len(blobs_b) }")
+
+ blobs_r[:] = [b for b in blobs_r if (b.convexity() < 0.7 and b.area() > 64)]
+ blobs_b[:] = [b for b in blobs_b if (b.convexity() < 0.7 and b.area() > 64)]
+ #print(f"new: { len(blobs_r) + len(blobs_b) }")
+
+
+ ######## Read signs
+ img = img.to_grayscale()
+ sign_buffer = 0x00
+ if(len(blobs_r) > 0 or len(blobs_b) > 0):
+ kpts_img = img.find_keypoints(max_keypoints=255, threshold=kpts_threshold, corner_detector=kpts_corner)
+
+ for index, b in enumerate(blobs_r):
+ sign_buffer = read_red_sign(b, img, kpts_img)
+
+ #for index, b in enumerate(blobs_b):
+ #sign_buffer = read_blu_sign(b, img, kpts_img)
+ return sign_buffer
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/speed.orb b/nicla/speed.orb
new file mode 100644
index 0000000..5c48d10
--- /dev/null
+++ b/nicla/speed.orb
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/temp.orb b/nicla/temp.orb
new file mode 100644
index 0000000..ec41eff
--- /dev/null
+++ b/nicla/temp.orb
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