From 051f0284c9895282205632087a2de6d163073cee Mon Sep 17 00:00:00 2001 From: NielsCoding <48092678+heavydemon21@users.noreply.github.com> Date: Tue, 6 Jun 2023 20:30:44 +0200 Subject: WIP final integration --- nicla/.Trashes/._501 | Bin 0 -> 4096 bytes nicla/.Trashes/501/._image.png | Bin 0 -> 4096 bytes nicla/.Trashes/501/._temp.mjpeg | 0 nicla/.Trashes/501/image.png | Bin 0 -> 20357 bytes nicla/.Trashes/501/temp.mjpeg | Bin 0 -> 4096 bytes nicla/._end.jpg | Bin 0 -> 4096 bytes nicla/._image.jpg | Bin 0 -> 4096 bytes nicla/._no_entry.jpg | Bin 0 -> 4096 bytes nicla/._speed.jpg | Bin 0 -> 4096 bytes nicla/._stop.jpg | Bin 0 -> 4096 bytes nicla/._temp.orb | Bin 0 -> 4096 bytes nicla/.fseventsd/fseventsd-uuid | 1 + nicla/ERROR.LOG | 1 + nicla/README.txt | 17 +++++++++++ nicla/end.jpg | Bin 0 -> 10829 bytes nicla/image.jpg | Bin 0 -> 30111 bytes nicla/kpts.orb | Bin 0 -> 2696 bytes nicla/no_entry.jpg | Bin 0 -> 16864 bytes nicla/road.py | 32 ++++++++++++-------- nicla/signs_detect.py | 64 ++++++++++++++++++++++++++++++++++++++++ nicla/speed.jpg | Bin 0 -> 27055 bytes nicla/speed.orb | Bin 0 -> 4096 bytes nicla/stop.jpg | Bin 0 -> 35442 bytes nicla/temp.orb | Bin 0 -> 6308 bytes 24 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 nicla/.Trashes/._501 create mode 100644 nicla/.Trashes/501/._image.png create mode 100644 nicla/.Trashes/501/._temp.mjpeg create mode 100644 nicla/.Trashes/501/image.png create mode 100644 nicla/.Trashes/501/temp.mjpeg create mode 100644 nicla/._end.jpg create mode 100644 nicla/._image.jpg create mode 100644 nicla/._no_entry.jpg create mode 100644 nicla/._speed.jpg create mode 100644 nicla/._stop.jpg create mode 100644 nicla/._temp.orb create mode 100644 nicla/.fseventsd/fseventsd-uuid create mode 100644 nicla/ERROR.LOG create mode 100644 nicla/README.txt create mode 100644 nicla/end.jpg create mode 100644 nicla/image.jpg create mode 100644 nicla/kpts.orb create mode 100644 nicla/no_entry.jpg create mode 100644 nicla/signs_detect.py create mode 100644 nicla/speed.jpg create mode 100644 nicla/speed.orb create mode 100644 nicla/stop.jpg create mode 100644 nicla/temp.orb (limited to 'nicla') diff --git a/nicla/.Trashes/._501 b/nicla/.Trashes/._501 new file mode 100644 index 0000000..338bd7b Binary files /dev/null and b/nicla/.Trashes/._501 differ diff --git a/nicla/.Trashes/501/._image.png b/nicla/.Trashes/501/._image.png new file mode 100644 index 0000000..02cf786 Binary files /dev/null and b/nicla/.Trashes/501/._image.png differ diff --git a/nicla/.Trashes/501/._temp.mjpeg b/nicla/.Trashes/501/._temp.mjpeg new file mode 100644 index 0000000..e69de29 diff --git a/nicla/.Trashes/501/image.png b/nicla/.Trashes/501/image.png new file mode 100644 index 0000000..d8bc7f5 Binary files /dev/null and b/nicla/.Trashes/501/image.png differ diff --git a/nicla/.Trashes/501/temp.mjpeg b/nicla/.Trashes/501/temp.mjpeg new file mode 100644 index 0000000..577a50a Binary files /dev/null and b/nicla/.Trashes/501/temp.mjpeg differ diff --git a/nicla/._end.jpg b/nicla/._end.jpg new file mode 100644 index 0000000..c26df8c Binary files /dev/null and b/nicla/._end.jpg differ diff --git a/nicla/._image.jpg b/nicla/._image.jpg new file mode 100644 index 0000000..4520888 Binary files /dev/null and b/nicla/._image.jpg differ diff --git a/nicla/._no_entry.jpg b/nicla/._no_entry.jpg new file mode 100644 index 0000000..a22af57 Binary files /dev/null and b/nicla/._no_entry.jpg differ diff --git a/nicla/._speed.jpg b/nicla/._speed.jpg new file mode 100644 index 0000000..f3a3faf Binary files /dev/null and b/nicla/._speed.jpg differ diff --git a/nicla/._stop.jpg b/nicla/._stop.jpg new file mode 100644 index 0000000..4a47a5b Binary files /dev/null and b/nicla/._stop.jpg differ diff --git a/nicla/._temp.orb b/nicla/._temp.orb new file mode 100644 index 0000000..acfd770 Binary files /dev/null and b/nicla/._temp.orb 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 Binary files /dev/null and b/nicla/end.jpg differ diff --git a/nicla/image.jpg b/nicla/image.jpg new file mode 100644 index 0000000..51a3c75 Binary files /dev/null and b/nicla/image.jpg differ diff --git a/nicla/kpts.orb b/nicla/kpts.orb new file mode 100644 index 0000000..0c3e1e7 Binary files /dev/null and b/nicla/kpts.orb differ diff --git a/nicla/no_entry.jpg b/nicla/no_entry.jpg new file mode 100644 index 0000000..6b1c54b Binary files /dev/null and b/nicla/no_entry.jpg differ diff --git a/nicla/road.py b/nicla/road.py index 02867b8..27101ea 100644 --- a/nicla/road.py +++ b/nicla/road.py @@ -1,12 +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 @@ -33,14 +34,12 @@ def drive(driveImg): 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 = blob.area() 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 @@ -52,13 +51,22 @@ def drive(driveImg): steerByte = int((avg + 1.0) * (DUI_CMD_STEER_END - DUI_CMD_STEER_START) / 2 + DUI_CMD_STEER_START) uart.uart_buffer(steerByte) sensor.dealloc_extra_fb() - +count = 0 while(True): - img = sensor.snapshot() - data = traffic_light.traf_lights(img) - if data is not None: - print(data) - uart.uart_buffer(data) - drive(img) - #uart.uart_buffer(DUI_CMD_SPEED_END) - clock.tick() + if count == 0: + count = count + 1 + speed = signs_detect.init_kpts("speed") + #stop = signs_detect.init_kpts("stop") + #car = signs_detect.init_kpts("image") + else: + img = sensor.snapshot() + data = traffic_light.traf_lights(img) + if data is not None: + uart.uart_buffer(data) + + #data_sign = signs_detect.sign_detection(img) + #if data_sign is not None: + #uart.uart_buffer(data_sign) + + 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..775ac15 --- /dev/null +++ b/nicla/signs_detect.py @@ -0,0 +1,64 @@ +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) + temp_img.dealloc_extra_fb() + 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_sign): + img = img_sign.copy() + ######## 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) + sensor.dealloc_extra_fb() + return sign_buffer diff --git a/nicla/speed.jpg b/nicla/speed.jpg new file mode 100644 index 0000000..c6cf7a9 Binary files /dev/null and b/nicla/speed.jpg differ diff --git a/nicla/speed.orb b/nicla/speed.orb new file mode 100644 index 0000000..5c48d10 Binary files /dev/null and b/nicla/speed.orb differ diff --git a/nicla/stop.jpg b/nicla/stop.jpg new file mode 100644 index 0000000..cd35e95 Binary files /dev/null and b/nicla/stop.jpg differ diff --git a/nicla/temp.orb b/nicla/temp.orb new file mode 100644 index 0000000..ec41eff Binary files /dev/null and b/nicla/temp.orb differ -- cgit v1.2.3