Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import os
  2. import cv2
  3. import sys
  4.  
  5. def genGood():
  6.  
  7. count = 0
  8. f = open("Good.dat", 'w')
  9. for i in range(1, 588):
  10. imagePath = "GirlsFaces/" + str(i) +".jpg"
  11. faceCascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
  12. print(imagePath)
  13. image = cv2.imread(imagePath, 1)
  14. gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  15.  
  16. faces = faceCascade.detectMultiScale(
  17. gray,
  18. scaleFactor=1.1,
  19. minNeighbors=5,
  20. minSize=(30, 30),
  21. flags = cv2.CASCADE_SCALE_IMAGE
  22. )
  23. print "Found {0} faces! {1}".format(len(faces), imagePath)
  24.  
  25. # Draw a rectangle around the faces
  26. if len(faces) == 1:
  27. f.write(imagePath + " ")
  28.  
  29. f.write(str(len(faces)) + " ")
  30. for (x, y, w, h) in faces:
  31. f.write(str(x) +" " + str(y) + " " + str(w) + " " + str(h))
  32. f.write("\n")
  33. #cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
  34. count += 1
  35. print (count)
  36. #cv2.imshow("Faces found", image)
  37. #cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement