1.效果

FaceDetection.png

2.代码

import cv2
import cvzone
from cvzone.FaceDetectionModule import FaceDetector

cap = cv2.VideoCapture(0)
detector = FaceDetector(minDetectionCon=0.4, modelSelection=0)

while True:
    success, img = cap.read()

    img, bboxs = detector.findFaces(img, draw=True)

    if bboxs:
        for bbox in bboxs:

            center = bbox['center']
            x, y, w, h = bbox['bbox']
            score = int(bbox['score'][0] * 100)

            cv2.circle(img, center, 5, (255, 0, 255), cv2.FILLED)
            cvzone.putTextRect(img, f'{score}%', (x, y - 20))
            cvzone.cornerRect(img, (x, y, w, h))

    cv2.imshow('img', img)
    cv2.waitKey(1)

3.注意事项!!!

包名

版本

python

3.10.14

cvzone

1.6.1

mediapipe

0.10.3

numpy

1.23.5

pyserial

3.5

tensorflow

2.12.0