aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nicla/signs_detect.py49
-rw-r--r--openMV/POC_signs_red.py48
2 files changed, 32 insertions, 65 deletions
diff --git a/nicla/signs_detect.py b/nicla/signs_detect.py
index 57b6c3e..baf62e8 100644
--- a/nicla/signs_detect.py
+++ b/nicla/signs_detect.py
@@ -1,10 +1,14 @@
-import sensor, image
+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.
-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
@@ -15,7 +19,7 @@ def match_kpts(kpts0, kpts1):
#print("matched:%d dt:%d"%(match.count(), match.theta()))
if match.count() > 0:
print(match.count())
- return match.count() > 0
+ return match.count() > 1
else:
return 0
@@ -23,21 +27,33 @@ 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
+ print("stop")
+
if match_kpts(kpts, speed):
img.draw_rectangle(val.rect())
- #print("speed")
- return 0x02
+ print("speed")
+
if match_kpts(kpts, car):
img.draw_rectangle(val.rect())
- #print("car")
- return 0x03
+ print("car")
#def read_red_sign(val, img, kpts):
-def sign_detection(img):
+
+kpts_threshold = 20
+kpts_corner = image.CORNER_FAST
+
+speed = init_kpts("speed")
+stop = init_kpts("stop")
+car = init_kpts("image")
+
+
+while(True):
+ clock.tick() # Update the FPS clock.
+ img = sensor.snapshot() # Take a picture and return the image.
+
######## 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) }")
@@ -49,13 +65,12 @@ def sign_detection(img):
######## 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)
+ 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
+ for index, b in enumerate(blobs_b):
+ read_blu_sign(b, img, kpts_img)
diff --git a/openMV/POC_signs_red.py b/openMV/POC_signs_red.py
deleted file mode 100644
index cb521b9..0000000
--- a/openMV/POC_signs_red.py
+++ /dev/null
@@ -1,48 +0,0 @@
-# Hello World Example
-#
-# Welcome to the OpenMV IDE! Click on the green run arrow button below to run the script!
-
-import sensor, image, time
-
-# Color Tracking Thresholds (Grayscale Min, Grayscale Max)
-min_rgb = 128
-max_rgb = 255
-threshold_list = [(min_rgb, max_rgb)]# only bright grey colours will get tracked.
-threshold_rgb = [(0, 100, 75, 32, 2, 127)] #only find red
-#threshold_rgb = [(18, 78, -8, 127, 24, 127)]
-
-sensor.reset() # Reset and initialize the sensor.
-sensor.set_pixformat(sensor.RGB565) # Set pixel format to RGB565 (or GRAYSCALE)
-#sensor.set_pixformat(sensor.GRAYSCALE)
-sensor.set_framesize(sensor.QVGA) # 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.
-
-while(True):
- clock.tick() # Update the FPS clock.
- img = sensor.snapshot() # Take a picture and return the image.
-
- #lines = img.find_lines()
- #for i in lines:
- #img.draw_line(i.line(), 255, 8)
-
- #gray = img
- #gray.to_grayscale()
- #img.find_edges(0)
-
-
-
- blobs = img.find_blobs(threshold_rgb)
- #blobs.count()
- #print(blobs)
- ##kpts = img.find_keypoints()
- for index, b in enumerate(blobs, 1):
- convex = b.convexity()
- if convex < 0.8:
- img.draw_rectangle(b.rect(),int((512+256)*convex),2)
- print(b.convexity())
-
- #img.draw_line(12,12,200,200,255,8)
-
- print(clock.fps()) # Note: OpenMV Cam runs about half as fast when connected
- # to the IDE. The FPS should increase once disconnected.