Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import cv2
- import glob
- def main():
- classifier = cv2.CascadeClassifier("lbpcascade_animeface.xml")
- count = 0
- origin_dir = ""
- img_path = os.path.abspath("./"+origin_dir)
- img_files = glob.glob(img_path+"/*.jpg")
- output_path = "./output"
- if not os.path.exists(output_path):
- os.makedirs(output_path)
- for img_file in img_files:
- image = cv2.imread(img_file)
- gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
- faces = classifier.detectMultiScale(gray)
- for coord in faces:
- if coord[2]>100:
- face_image = image[coord[1]: coord[1] + coord[3], coord[0]: coord[0] + coord[2]]
- output = output_path+"/"+origin_dir+"_%d.jpg"%count
- cv2.imwrite(output,face_image)
- count += 1
- if __name__ == '__main__':
- main()
Add Comment
Please, Sign In to add comment