keypoints.py
# هذا العمل مرخص بموجب ترخيص MIT.
# حقوق النشر (c) 2013-2023 OpenMV LLC. جميع الحقوق محفوظة.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# مثال تتبع الأجسام باستخدام النقاط المميزة (keypoints).
# أرِ الكاميرا جسمًا ثم شغّل السكربت. سيتم استخراج مجموعة من النقاط المميزة
# مرة واحدة ثم يتم تتبعها في الإطارات التالية. إذا أردت مجموعة جديدة من النقاط المميزة، أعد تشغيل
# السكربت. ملاحظة: راجع الوثائق لمعرفة المعاملات لضبط find_keypoints و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
# ملاحظة: قم بإلغاء التعليق لتحميل واصف النقاط المميزة (descriptor) من ملف
# 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:
# ملاحظة: بشكل افتراضي، تُرجع find_keypoints نقاطًا مميزة متعددة المقاييس مستخرجة من هرم الصورة (image pyramid).
kpts1 = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2)
draw_keypoints(img, kpts1)
else:
# ملاحظة: عند استخراج النقاط المميزة لمطابقة الواصف الأول، نستخدم normalized=True لاستخراج
# النقاط المميزة من المقياس الأول فقط، والذي سيطابق أحد المقاييس في الواصف الأول.
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:
# إذا كان لدينا n مطابقة جيدة على الأقل
# رسم المستطيل المحيط والعلامة الصليبية.
img.draw_detection(match, size=10)
print(kpts2, "matched:%d dt:%d" % (match.count, match.theta))
# ملاحظة: قم بإلغاء التعليق إذا أردت رسم النقاط المميزة
# img.draw_keypoints(kpts2, size=KEYPOINTS_SIZE, matched=True)
# رسم معدل الإطارات (FPS)
img.draw_string((0, 0), "FPS:%.2f" % (clock.fps()))