基于关键点的物体追踪示例
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
clock = time.clock()
while True:
clock.tick()
img = csi0.snapshot()
if kpts1 is None:
kpts1 = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2)
draw_keypoints(img, kpts1)
else:
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:
img.draw_detection(match, size=10)
print(kpts2, "matched:%d dt:%d" % (match.count, match.theta))
img.draw_string((0, 0), "FPS:%.2f" % (clock.fps()))