face_landmarks_multi_face.py

# هذا العمل مرخص بموجب ترخيص MIT.
# حقوق النشر (c) 2013-2025 لشركة OpenMV LLC. جميع الحقوق محفوظة.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# يوضح هذا المثال نموذج MediaPipe من Google لاكتشاف معالم الوجه لعدة وجوه.
#
# ملاحظة: يتطلب هذا المثال كاميرا OpenMV مزودة بوحدة NPU مثل AE3 أو N6 للعمل في الوقت الفعلي.

import csi
import time
import ml
from ml.preprocessing import Normalization
from ml.postprocessing.mediapipe import BlazeFace
from ml.postprocessing.mediapipe import FaceLandmarks

# تهيئة المستشعر.
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)

# يتطلب BlazeFace صورة مربعة للحصول على أفضل النتائج.
# يعمل FaceLandmarks مع الصور غير المربعة من مقتطفات BlazeFace.
csi0.window((400, 400))

# تحميل نموذج اكتشاف الوجوه المدمج
face_detection = ml.Model("/rom/blazeface_front_128.tflite", postprocess=BlazeFace(threshold=0.4))
print(face_detection)

# تحميل نموذج معالم الوجه المدمج
face_landmarks = ml.Model("/rom/face_landmarks_192.tflite", postprocess=FaceLandmarks(threshold=0.4))
print(face_landmarks)

clock = time.clock()
while True:
    clock.tick()
    img = csi0.snapshot()

    # faces هي قائمة من مجموعات ((x, y, w, h), score, keypoints)
    for r, score, keypoints in face_detection.predict([img]):
        # rect هو (x, y, w, h) - قم بتكبيره مرتين لنموذج معالم الوجه
        wider_rect = (r[0] - r[2] // 2, r[1] - r[3] // 2, r[2] * 2, r[3] * 2)
        # العمل فقط على منطقة اهتمام (ROI) الوجه المكتشف
        n = Normalization(roi=wider_rect)

        # marks هي قائمة من مجموعات ((x, y, w, h), score, keypoints)
        for r, score, keypoints in face_landmarks.predict([n(img)]):
            ml.utils.draw_predictions(img, [r], ("face",), ((0, 0, 255),), format=None)

            # keypoints هي مصفوفة ndarray بشكل (468, 3) حيث كل نقطة مميزة هي (x, y, z)
            ml.utils.draw_keypoints(img, keypoints, radius=0, color=(255, 0, 0))

    print(clock.fps(), "fps")

results matching ""

    No results matching ""