forked from boostcampaitech6/level2-3-cv-finalproject-cv-08
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81f5f99
commit e399ea0
Showing
6 changed files
with
204 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
opencv-python | ||
rembg | ||
librosa | ||
numpy | ||
matplotlib | ||
soundfile | ||
pydub | ||
pandas | ||
moviepy | ||
face_recognition | ||
selenium | ||
requests | ||
beautifulsoup4 | ||
pytube | ||
transformers | ||
Pillow | ||
torch | ||
facenet-pytorch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,41 @@ | ||
import cv2 | ||
|
||
face_cascade = cv2.CascadeClassifier('code/file/haarcascade_frontalface_default.xml') | ||
|
||
# 이미지 읽기 | ||
img = cv2.imread('code/file/image.png') | ||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | ||
|
||
# 얼굴 감지 | ||
faces = face_cascade.detectMultiScale(gray, 1.3, 5) | ||
|
||
# 각 얼굴에 대해 반복 | ||
for (x, y, w, h) in faces: | ||
# 얼굴 영역에 사각형 그리기 | ||
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2) | ||
|
||
# 얼굴 영역을 256x256 크기로 조정 | ||
face_crop = cv2.resize(img[y:y+h, x:x+w], (256, 256)) | ||
def detect_and_save_faces(image_path, output_path): | ||
"""Detects faces in the input image and saves them as 256x256 pixel images. | ||
# 얼굴 이미지 저장 | ||
cv2.imwrite('code/file/face_detected_256x256.png', face_crop) | ||
|
||
# 이미지 보여주기 | ||
cv2.imshow('Image view', img) | ||
|
||
# 'q' 키를 누를 때까지 대기 | ||
while cv2.waitKey(0) & 0xFF != ord('q'): | ||
pass | ||
|
||
cv2.destroyAllWindows() | ||
|
||
Args: | ||
image_path (str): Path to the input image file. | ||
output_path (str): Path to save the detected face images. | ||
""" | ||
# Load the pre-trained face cascade classifier | ||
face_cascade = cv2.CascadeClassifier('code/file/haarcascade_frontalface_default.xml') | ||
|
||
# Read the input image | ||
img = cv2.imread(image_path) | ||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | ||
|
||
# Detect faces | ||
faces = face_cascade.detectMultiScale(gray, 1.3, 5) | ||
|
||
# Iterate over each detected face | ||
for (x, y, w, h) in faces: | ||
# Draw rectangle around the face | ||
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2) | ||
|
||
# Resize the face region to 256x256 pixels | ||
face_crop = cv2.resize(img[y:y+h, x:x+w], (256, 256)) | ||
|
||
# Save the face image | ||
cv2.imwrite(output_path, face_crop) | ||
|
||
# Display the image | ||
cv2.imshow('Image view', img) | ||
|
||
# Wait for 'q' key to be pressed | ||
while cv2.waitKey(0) & 0xFF != ord('q'): | ||
pass | ||
|
||
cv2.destroyAllWindows() | ||
|
||
# Example usage | ||
detect_and_save_faces('code/file/image.png', 'code/file/face_detected_256x256.png') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters