人脸检测(Face)
import cv2
import mediapipe as mp
from mediapipe.python.solutions.drawing_utils import DrawingSpec
mp_face_detection = mp.solutions.face_detection
mp_drawing = mp.solutions.drawing_utils
with mp_face_detection.FaceDetection(
min_detection_confidence=0.5, model_selection=0
) as face_detection:
cap = cv2.VideoCapture(0)
while True:
success, img = cap.read()
if success:
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = face_detection.process(imgRGB)
if results.detections is None:
continue
for face in results.detections:
color = DrawingSpec((255, 0, 255))
mp_drawing.draw_detection(img, face, color, color)
cv2.imshow('face', img)
if cv2.waitKey(1) > 0:
break
cap.release()
其它功能