From ee0e9822b77703db601819eac36c8198e40eefd3 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 7 Mar 2017 19:45:48 +0200 Subject: [PATCH] Update keypoints scripts. --- usr/examples/09-Feature-Detection/keypoints.py | 14 +++++++------- .../09-Feature-Detection/keypoints_save.py | 14 ++++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/usr/examples/09-Feature-Detection/keypoints.py b/usr/examples/09-Feature-Detection/keypoints.py index aea10bd02..38bdaba6e 100644 --- a/usr/examples/09-Feature-Detection/keypoints.py +++ b/usr/examples/09-Feature-Detection/keypoints.py @@ -8,14 +8,14 @@ import sensor, time, image sensor.reset() # Sensor settings -sensor.set_contrast(1) +sensor.set_contrast(3) sensor.set_gainceiling(16) sensor.set_framesize(sensor.VGA) -sensor.set_windowing((240, 240)) +sensor.set_windowing((320, 240)) sensor.set_pixformat(sensor.GRAYSCALE) -sensor.set_auto_gain(False, value=100) sensor.skip_frames(30) +sensor.set_auto_gain(False, value=100) def draw_keypoints(img, kpts): print(kpts) @@ -35,16 +35,16 @@ while (True): img = sensor.snapshot() if (kpts1 == None): # NOTE: By default find_keypoints returns multi-scale keypoints extracted from an image pyramid. - kpts1 = img.find_keypoints(max_keypoints=150, threshold=20, scale_factor=1.1) + kpts1 = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2) draw_keypoints(img, kpts1) else: # NOTE: When extracting keypoints to match the first descriptor, we use normalized=True to extract # keypoints from the first scale only, which will match one of the scales in the first descriptor. - kpts2 = img.find_keypoints(max_keypoints=150, threshold=20, normalized=True) + kpts2 = img.find_keypoints(max_keypoints=150, threshold=10, normalized=True) if (kpts2): - c = image.match_descriptor(kpts1, kpts2, threshold=80) + c = image.match_descriptor(kpts1, kpts2, threshold=85) match = c[6] # C[6] contains the number of matches. - if (match>5): + if (match>10): img.draw_rectangle(c[2:6]) img.draw_cross(c[0], c[1], size=10) diff --git a/usr/examples/09-Feature-Detection/keypoints_save.py b/usr/examples/09-Feature-Detection/keypoints_save.py index b7dcfb40e..811073feb 100644 --- a/usr/examples/09-Feature-Detection/keypoints_save.py +++ b/usr/examples/09-Feature-Detection/keypoints_save.py @@ -10,18 +10,23 @@ import sensor, time, image sensor.reset() # Sensor settings -sensor.set_contrast(1) +sensor.set_contrast(3) sensor.set_gainceiling(16) -sensor.set_framesize(sensor.QCIF) +sensor.set_framesize(sensor.VGA) +sensor.set_windowing((320, 240)) sensor.set_pixformat(sensor.GRAYSCALE) -sensor.set_auto_gain(False, value=100) sensor.skip_frames(30) +sensor.set_auto_gain(False, value=100) FILE_NAME = "desc" img = sensor.snapshot() # NOTE: See the docs for other arguments -kpts = img.find_keypoints(scale_factor=1.2) +# NOTE: By default find_keypoints returns multi-scale keypoints extracted from an image pyramid. +kpts = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2) + +if (kpts == None): + raise(Exception("Couldn't find any keypoints!")) image.save_descriptor(kpts, "/%s.orb"%(FILE_NAME)) img.save("/%s.pgm"%(FILE_NAME)) @@ -29,3 +34,4 @@ img.save("/%s.pgm"%(FILE_NAME)) img.draw_keypoints(kpts) sensor.snapshot() time.sleep(1000) +raise(Exception("Done! Please reset the camera"))