Guest User

Untitled

a guest
Feb 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. import numpy as np
  2. import cv2
  3.  
  4. face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
  5. eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
  6.  
  7. img = cv2.imread('sachin.jpg')
  8. gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  9.  
  10.  
  11. # We first detect the face then apply the eye detector inside the face region.
  12.  
  13. faces = face_cascade.detectMultiScale(gray, 1.3, 5)
  14.  
  15. for (x,y,w,h) in faces:
  16.  
  17. cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
  18. roi_gray = gray[y:y+h, x:x+w]
  19. roi_color = img[y:y+h, x:x+w]
  20. eyes = eye_cascade.detectMultiScale(roi_gray)
  21.  
  22. for (ex,ey,ew,eh) in eyes:
  23. cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
  24.  
  25. cv2.imshow('img',img)
  26. cv2.waitKey(0)
  27. cv2.destroyAllWindows()
Add Comment
Please, Sign In to add comment