Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. import os
  2. import cv2
  3. import sys
  4.  
  5. count = 0
  6. count1 = 0
  7. count2 = 0
  8. for imagePath in os.listdir("Good"):
  9. #imagePath = 'GirlsFaces/8.jpg'
  10. faceCascade1 = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
  11.  
  12. faceCascade = cv2.CascadeClassifier("cascadeGirls3.xml")
  13. faceCascade2 = cv2.CascadeClassifier("cascade.xml")
  14. faceCascade3 = cv2.CascadeClassifier("simplegirlcascade.xml")
  15.  
  16.  
  17. imagePath = "Good"+ "/" + imagePath
  18. # print(imagePath)
  19. image = cv2.imread(imagePath, 1)
  20. gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  21.  
  22.  
  23. faces = faceCascade2.detectMultiScale(
  24. gray,
  25. scaleFactor=1.1,
  26. minNeighbors=5,
  27. minSize=(30, 30),
  28. flags = cv2.CASCADE_SCALE_IMAGE
  29. )
  30.  
  31. #faces = faceCascade1.detectMultiScale(
  32. # gray,
  33. # scaleFactor=1.1,
  34. # minNeighbors=5,
  35. # minSize=(30, 30),
  36. # flags= cv2.CASCADE_SCALE_IMAGE
  37. #)
  38. #if len(faces) != 0:
  39. # print ('face!')
  40.  
  41. for (x, y, w, h) in faces:
  42. imag = image[y:y+h, x:x+w]
  43. gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  44.  
  45. faces1 = faceCascade.detectMultiScale(
  46. gray,
  47. scaleFactor=1.1,
  48. minNeighbors=5,
  49. minSize=(30, 30),
  50. flags = cv2.CASCADE_SCALE_IMAGE
  51. )
  52.  
  53. #print "Found {0} girls! {1}".format(len(faces1), imagePath)
  54. #print "Found {0} girls! {1}".format(len(faces2), imagePath)
  55.  
  56. # Draw a recta ngle around the faces
  57. if (len(faces1) != 0):
  58. count += 1
  59. #print("+")
  60. for (x, y, w, h) in faces:
  61. cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
  62.  
  63.  
  64.  
  65. # cv2.imshow("girls found1", image)
  66. # cv2.waitKey(0)
  67. #count+=1
  68.  
  69.  
  70. #print "Found {0} girls! {1}".format(len(faces1), imagePath)
  71. #print "Found {0} girls! {1}".format(len(faces2), imagePath)
  72.  
  73. # Draw a recta ngle around the faces
  74. if len(faces) != 0:
  75. count1+=1
  76. #print("-")
  77. for (x, y, w, h) in faces:
  78. cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
  79.  
  80. #cv2.imshow("girls found2", image)
  81. # cv2.waitKey(0)
  82.  
  83.  
  84.  
  85. #print "Found {0} girls! {1}".format(len(faces1), imagePath)
  86. #print "Found {0} girls! {1}".format(len(faces2), imagePath)
  87.  
  88. # Draw a recta ngle around the faces
  89. #if (len(faces1) != 0):
  90. # count2+=1
  91. # for (x, y, w, h) in faces:
  92. # cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
  93.  
  94.  
  95.  
  96. # cv2.imshow("girls found3", image)
  97. # cv2.waitKey(0)
  98. #count+=1
  99.  
  100. print (count, count1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement