Advertisement
skip420

face_deteck

Jan 7th, 2021
1,018
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. #python3 face_Detect.py image.jpg
  2.  
  3. #Facial_recognition_made_simply_with_python3
  4.  
  5.  
  6. import cv2
  7. import sys
  8.  
  9. # Get user supplied values
  10. imagePath = sys.argv[1]
  11. cascPath = "haarcascade_frontalface_default.xml"
  12.  
  13. # Create the haar cascade
  14. faceCascade = cv2.CascadeClassifier(cascPath)
  15.  
  16. # Read the image
  17. image = cv2.imread(imagePath)
  18. gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
  19.  
  20. # Detect faces in the image
  21. faces = faceCascade.detectMultiScale(
  22.     gray,
  23.     scaleFactor=1.1,
  24.     minNeighbors=5,
  25.     minSize=(30, 30),
  26.     #flags = cv2.cv.CV_HAAR_SCALE_IMAGE
  27. )
  28.  
  29. print("Found {0} faces!".format(len(faces)))
  30.  
  31. # Draw a rectangle around the faces
  32. for (x, y, w, h) in faces:
  33.     cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)
  34.  
  35. cv2.imshow("Faces found", image)
  36. cv2.waitKey(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement