



# 사전 학습된 cascade 파일 (.xml) 적용
face_cascade = cv2.CascadeClassifier('../DATA/haarcascades/haarcascade_frontalface_default.xml')
# 얼굴 탐지
def detect_face(img):
face_img = img.copy()
face_rects = face_cascade.detectMultiScale(face_img)
for (x,y,w,h) in face_rects:
cv2.rectangle(face_img, (x,y), (x+w,y+h), (255,255,255), 10)
return face_img
# 개선된 얼굴 탐지
def adj_detect_face(img):
face_img = img.copy()
face_rects = face_cascade.detectMultiScale(face_img,scaleFactor=1.2, minNeighbors=5)
for (x,y,w,h) in face_rects:
cv2.rectangle(face_img, (x,y), (x+w,y+h), (255,255,255), 10)
return face_img
detectMultiScale 메소드 Syntax
detectMultiScale 함수를 사용하여 다양한 크기의 얼굴을 검출합니다.scaleFactor=1.1: 각 이미지 스케일에서 크기가 10%씩 축소됩니다.minNeighbors=5: 객체 후보가 최소 5번 겹쳐진 경우에만 얼굴로 검출됩니다.minSize=(30, 30): 최소 한 변이 30 픽셀 이상의 객체만 검출됩니다.maxSize=(300, 300): 최대 한 변이 300 픽셀 이하의 객체만 검출됩니다.| 개선 전 | 개선 후 |
|---|---|