openmv/scripts/examples/Arduino/Nicla-Vision/09-Feature-Detection/keypoints_save.py
2022-06-21 11:39:37 +02:00

31 lines
1.0 KiB
Python

# Keypoints descriptor example.
# This example shows how to save a keypoints descriptor to file. Show the camera an object
# and then run the script. The script will extract and save a keypoints descriptor and the image.
# You can use the keypoints_editor.py util to remove unwanted keypoints.
#
# NOTE: Please reset the camera after running this script to see the new file.
import sensor, time, image
# Reset sensor
sensor.reset()
sensor.set_framesize(sensor.QVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.skip_frames(time = 2000)
FILE_NAME = "desc"
img = sensor.snapshot()
# NOTE: See the docs for other arguments
# 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))
img.draw_keypoints(kpts)
sensor.snapshot()
time.sleep_ms(1000)
raise(Exception("Done! Please reset the camera"))