Advertisement
Guest User

Untitled

a guest
Oct 1st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # Import the required modules
  4. import cv2, os
  5. import numpy as np
  6. import mysql.connector
  7. from PIL import Image
  8. import argparse
  9. import time
  10. print cv2. __version__
  11. homeDir = os.environ['HOME']
  12. databaseName = 'FaceDatabase'
  13.  
  14. cnx = mysql.connector.connect(user='root',
  15. password='wojtek123',
  16. host='127.0.0.1',
  17. database=databaseName)
  18. cursor = cnx.cursor()
  19.  
  20.  
  21.  
  22. cascadePath = "pyt face rec/haarcascade_frontalface_default.xml"
  23. faceCascade = cv2.CascadeClassifier(cascadePath)
  24. def extract_face():
  25. image_pil = Image.open(homeDir + image_path).convert('L')
  26. image = np.array(image_pil, 'uint8')
  27. faces = faceCascade.detectMultiScale(image)
  28. for (x, y, w, h) in faces:
  29. image = image[y: y + h, x: x + w]
  30. resizedImage = cv2.resize(image, (96, 96))
  31. im = Image.fromarray(resizedImage)
  32. newPath = image_path.replace("centered", "cropped")
  33. im.save(homeDir + newPath)
  34.  
  35. extract_face();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement