-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrop.py
More file actions
31 lines (21 loc) · 945 Bytes
/
crop.py
File metadata and controls
31 lines (21 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
import cv2
path_dir = "/Users/younglimmm/PycharmProjects/FindingIdeal/image/validation/cat/"
file_list = os.listdir(path_dir)
print(len(file_list))
file_name_list = []
for i in range(len(file_list)):
file_name_list.append(file_list[i].replace(".jpg", ""))
def cutting_face_save(image, names):
face_cascade = cv2.CascadeClassifier(
'/Users/younglimmm/PycharmProjects/FindingIdealAI/haarcascade_frontalface_default.xml')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
cropped = image[y: y + h, x: x + w]
resize = cv2.resize(cropped, (180, 180))
cv2.imwrite(f"images/validation/dinosaur/{names}.jpg", resize)
for name in file_name_list:
img = cv2.imread("/Users/younglimmm/PycharmProjects/FindingIdealAI/image/validation/dinosaur/"+name+".jpg")
print(img)
cutting_face_save(img, name)