Guest User

Untitled

a guest
Sep 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. import cv2
  2. import os
  3. cam = cv2.VideoCapture(0)
  4. cam.set(3, 640)
  5. cam.set(4, 480)
  6. face_detector = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
  7. #face_id = input('n id: ')
  8. print("n [INFO] Initializing face capture. Look the camera and wait ...")
  9. count = 1
  10. face_id = 1
  11. while(True):
  12. ret, img = cam.read()
  13. img = cv2.flip(img, 1)
  14. gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  15. faces = face_detector.detectMultiScale(gray, 1.3, 5)
  16. for (x,y,w,h) in faces:
  17. cv2.rectangle(img, (x,y), (x+w,y+h), (255,0,0), 2)
  18. count += 1
  19. if os.path.exists("dataset/User.%s.1.jpg" % face_id):
  20. face_id + 1
  21. cv2.imwrite("dataset/User." + str(face_id) + '.' + str(count) + ".jpg", gray[y:y+h,x:x+w])
  22. cv2.imshow('image', img)
  23. k = cv2.waitKey(100) & 0xff
  24. if k == 27:
  25. break
  26. elif count >= 30:
  27. break
  28. print("n [INFO] Exiting Program and cleanup stuff")
  29. cam.release()
  30. cv2.destroyAllWindows()
  31.  
  32. if os.path.exists("dataset/User.%s.1.jpg" % face_id):
  33. face_id + 1
  34.  
  35. while os.path.exists("dataset/User.%s.1.jpg" % face_id):
  36. face_id + 1
Add Comment
Please, Sign In to add comment