Face Detection
2024.01.09 - [study/Udemy] - [CVM] 1. Face Detection
2024.01.27 - [study/Udemy] - [CVM] 2. Face Detection (2)
주제 4. Eye Detection with haarcascades
- 이미지에서 다른 유형의 개체를 감지하려면 사전 학습이 된 모델이 필요하다.
- cv2.CascadeClassifier를 활용해서 사전 학습이 된 모델을 eye_detector로 불러온다.
import cv2
#- 얼굴 탐지 분류기
face_detector = cv2.CascadeClassifier('/content/drive/MyDrive/haarcascade_frontalface_default.xml')
#- 눈 탐지 분류기
eye_detector = cv2.CascadeClassifier('/content/drive/MyDrive/haarcascade_eye.xml')
- 얼굴 탐지한 것과 마찬가지로 매개변수들(scaleFactor, minNeighbors, minSize등)을 변경해가며 탐지 정확도를 높여줄 수 있다.
image = cv2.imread('/content/drive/MyDrive/people1.jpg')
#image = cv2.resize(image, (800, 600))
print(image.shape)
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
#-- face detection
face_detections = face_detector.detectMultiScale(image_gray, scaleFactor = 1.3,
minSize = (30,30))
for (x, y, w, h) in face_detections:
cv2.rectangle(image, (x, y), (x + w, y + h), (0,255,0), 2)
#-- eye detection
eye_detections = eye_detector.detectMultiScale(image_gray, scaleFactor = 1.1,
minNeighbors=10, maxSize=(70,70))
for (x, y, w, h) in eye_detections:
print(w, h)
cv2.rectangle(image, (x, y), (x + w, y + h), (0,0,255), 2)
cv2_imshow(image)
반응형
'Study > Udemy' 카테고리의 다른 글
[CVM] 2. Face Detection (2) (0) | 2024.01.27 |
---|---|
[CVM] 1. Face Detection (1) | 2024.01.09 |