반응형
Notice
Recent Posts
Recent Comments
- Today
- Total
작심삼일
[MediaPipe] MediaPipe로 face detection하기 본문
728x90
반응형
코드
mediapipe.solution의 face_detection을 사용한다.
face_detection.process를 진행하면 여러 데이터들이 나오는데, 그 중 bounding box만 뽑기 위해서는 아래와 같이 results.detections[0].location_data.relative_bounding_box을 사용한다.
import mediapipe as mp
import cv2
mp_face_detection = mp.solutions.face_detection
face_detection = mp_face_detection.FaceDetection(model_selection=1, min_detection_confidence=0.5)
img_path = './gunter.png'
img = cv2.imread(img_path)
results = face_detection.process(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
bbox = results.detections[0].location_data.relative_bounding_box # 첫번째 얼굴의 bounding box
# 두번째 얼굴을 찾고싶다면
# results.detections[1].location_data.relative_bounding_box
h, w, _ = img.shape
face = img[int(h*bbox.ymin):int(h*bbox.ymin)+int(h*bbox.height), int(w*bbox.xmin):int(w*bbox.xmin)+int(w*bbox.width)]
728x90
반응형
'정리 > Python library' 카테고리의 다른 글
[conda] conda install (0) | 2023.10.18 |
---|
Comments