keypoints.py

# Questo lavoro è concesso in licenza MIT.
# Copyright (c) 2013-2023 OpenMV LLC. Tutti i diritti riservati.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# Esempio di tracciamento di oggetti con keypoint.
# Mostrare un oggetto alla fotocamera e poi eseguire lo script. Verrà estratto un set di keypoint
# una volta e poi tracciato nei fotogrammi successivi. Se si desidera un nuovo set di keypoint, rieseguire
# lo script. NOTA: consultare la documentazione per gli argomenti per regolare find_keypoints e match_keypoints.
import csi
import time
import image

csi0 = csi.CSI()
csi0.reset()
csi0.contrast(3)
csi0.gainceiling(16)
csi0.framesize(csi.VGA)
csi0.window((320, 240))
csi0.pixformat(csi.GRAYSCALE)

csi0.snapshot(time=2000)
csi0.auto_gain(False, gain_db=100)


def draw_keypoints(img, kpts):
    if kpts:
        print(kpts)
        img.draw_keypoints(kpts)
        img = csi0.snapshot()
        time.sleep_ms(1000)


kpts1 = None
# NOTA: decommentare per caricare un descrittore di keypoint da file
# kpts1 = image.load_descriptor("desc.orb")
# img = csi0.snapshot()
# draw_keypoints(img, kpts1)

clock = time.clock()
while True:
    clock.tick()
    img = csi0.snapshot()
    if kpts1 is None:
        # NOTA: per impostazione predefinita, find_keypoints restituisce keypoint multi-scala estratti da una piramide di immagini.
        kpts1 = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2)
        draw_keypoints(img, kpts1)
    else:
        # NOTA: quando si estraggono i keypoint per confrontarli con il primo descrittore, si usa normalized=True per estrarre
        # i keypoint solo dalla prima scala, che corrisponderà a una delle scale nel primo descrittore.
        kpts2 = img.find_keypoints(max_keypoints=150, threshold=10, normalized=True)
        if kpts2:
            match = image.match_descriptor(kpts1, kpts2, threshold=85)
            if match.count > 10:
                # Se abbiamo almeno n "buone corrispondenze"
                # Disegna il rettangolo di delimitazione e la croce.
                img.draw_detection(match, size=10)

            print(kpts2, "matched:%d dt:%d" % (match.count, match.theta))
            # NOTA: decommentare se si desidera disegnare i keypoint
            # img.draw_keypoints(kpts2, size=KEYPOINTS_SIZE, matched=True)

    # Disegna gli FPS
    img.draw_string((0, 0), "FPS:%.2f" % (clock.fps()))

results matching ""

    No results matching ""