Guest User

Untitled

a guest
Apr 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import os
  2. import cv2
  3. import glob
  4.  
  5. def main():
  6. classifier = cv2.CascadeClassifier("lbpcascade_animeface.xml")
  7.  
  8. count = 0
  9. origin_dir = ""
  10. img_path = os.path.abspath("./"+origin_dir)
  11. img_files = glob.glob(img_path+"/*.jpg")
  12. output_path = "./output"
  13. if not os.path.exists(output_path):
  14. os.makedirs(output_path)
  15. for img_file in img_files:
  16. image = cv2.imread(img_file)
  17. gray = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
  18. faces = classifier.detectMultiScale(gray)
  19.  
  20. for coord in faces:
  21. if coord[2]>100:
  22. face_image = image[coord[1]: coord[1] + coord[3], coord[0]: coord[0] + coord[2]]
  23. output = output_path+"/"+origin_dir+"_%d.jpg"%count
  24. cv2.imwrite(output,face_image)
  25. count += 1
  26.  
  27. if __name__ == '__main__':
  28. main()
Add Comment
Please, Sign In to add comment