aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nicla/road.py29
-rw-r--r--nicla/signs_detect.py67
2 files changed, 55 insertions, 41 deletions
diff --git a/nicla/road.py b/nicla/road.py
index 2c4e84a..43602fd 100644
--- a/nicla/road.py
+++ b/nicla/road.py
@@ -2,8 +2,12 @@ import sensor, image, time, math
import uart
import signs_detect
import traffic_light
+from garbage_filter import garbage_filter
from consts import *
+buffer_lights = list()
+buffer_signs = list()
+
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.HVGA)
@@ -76,21 +80,24 @@ def drive(img):
uart.uart_buffer(steerByte)
-traffic_buffer = CircularBuffer(2)
-sign_buffer = CircularBuffer(3)
+
+
while(True):
- img = sensor.snapshot()
- data = traffic_buffer.add(traffic_light.traf_lights(img))
- if data is not None:
- uart.uart_buffer(data)
+ #img = sensor.snapshot()
+ #data = traffic_light.traf_lights(img)
+ #new_data = garbage_filter(buffer_lights,data,3,21)
+ #if new_data is not None:
+ #uart.uart_buffer(data)
sign_img = sensor.snapshot()
- data = sign_buffer.add(signs_detect.sign_detection(sign_img))
- if data is not None:
+ data = signs_detect.sign_detection(sign_img)
+ new_data = garbage_filter(buffer_signs,data,3,21)
+
+ if new_data is not None:
uart.uart_buffer(data)
- drive_img = sensor.snapshot()
- drive(drive_img)
- uart.uart_buffer(0x1f)
+ #drive_img = sensor.snapshot()
+ #drive(drive_img)
+ #uart.uart_buffer(0x1f)
diff --git a/nicla/signs_detect.py b/nicla/signs_detect.py
index 70bc633..86d85d7 100644
--- a/nicla/signs_detect.py
+++ b/nicla/signs_detect.py
@@ -1,14 +1,10 @@
-import sensor, image, time
-
-sensor.reset() # Reset and initialize the sensor.
-sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
-sensor.set_framesize(sensor.HVGA) # Set frame size to QVGA (320x240)
-sensor.skip_frames(time = 2000) # Wait for settings take effect.
-clock = time.clock() # Create a clock object to track the FPS.
+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 = 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
@@ -22,34 +18,36 @@ def match_kpts(kpts0, kpts1):
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() > 0
+ #print(match.count())
+ return match.count() > 0
else:
return 0
def read_red_sign(val, img, kpts):
- data = 0x00
- if match_kpts(kpts, stop):
+ data = 0x02
+ # if match_kpts(kpts, stop):
+ # #img.draw_rectangle(val.rect())
+ # #img.draw_cross(match.cx(), match.cy(), size=10)
+ # #print("stop")
+ # data = 0x01
+ # elif match_kpts(kpts, speed):
+ # #img.draw_rectangle(val.rect())
+ # #print("speed")
+ # data = 0x02
+ # elif match_kpts(kpts, car):
#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
+ #data = 0x03
+
+ return data
-#def read_red_sign(val, img, kpts):
+def read_blu_sign(val, img, kpts):
+ return 0x03
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)])
+ blobs_b = img.find_blobs([(25, 69, 49, 9, -12, -71)])
#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)]
@@ -58,14 +56,23 @@ def sign_detection(img):
######## Read signs
- img = img.to_grayscale()
-
+ # img = img.to_grayscale()
+ sign_buffer = 0x01
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)
+ # img.draw_rectangle(b.rect())
+ sign_buffer = 0x02
+ # sign_buffer = read_red_sign(b, img, kpts_img)
+ # if sign_buffer != 0x01:
+ # break
+
+ for index, b in enumerate(blobs_b):
+ # img.draw_rectangle(b.rect(),0)
+ sign_buffer = 0x03
+ # sign_buffer = read_blu_sign(b, img, kpts_img)
+ # if sign_buffer != 0x01:
+ # break
- #for index, b in enumerate(blobs_b):
- #sign_buffer = read_blu_sign(b, img, kpts_img)
return sign_buffer