Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. face-recognition
  2.  
  3. import cv2
  4. import numpy as np
  5. import pickle
  6. import tweepy
  7. import tweet
  8. import time
  9.  
  10. face_cascade = cv2.CascadeClassifier('opencv-files/haarcascade_frontalface_alt2.xml')
  11. recognizer = cv2.face.LBPHFaceRecognizer_create()
  12. recognizer.read("trainer.yml")
  13.  
  14. labels = {"person_name": 0}
  15. with open("labels.pickle", 'rb') as f:
  16. og_labels = pickle.load(f)
  17. labels = {v:k for k,v in og_labels.items()}
  18.  
  19. vc = cv2.VideoCapture(0) #command open webcam
  20.  
  21.  
  22. while True:
  23. ret, frame = vc.read() #read webcam
  24. gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) #change color to gray
  25. faces = face_cascade.detectMultiScale(gray, scaleFactor=1.2, minNeighbors=5) #scaling face movement
  26. for (x, y, w, h) in faces:
  27. #print(x, y, w, h)
  28. roi_gray = gray[y:y+h, x:x+w]
  29. roi_color = frame[y:y+h, x:x+w]
  30.  
  31. id_, conf = recognizer.predict(roi_gray)
  32. if conf >= 10 and conf <= 75:
  33. #print(id_)
  34. print(labels[id_])
  35. font = cv2.FONT_HERSHEY_SIMPLEX
  36. name = labels[id_]
  37. nama = labels[id_]
  38. color = (255, 255, 255)
  39. stroke = 2
  40. cv2.putText(frame, name, (x,y), font, 1, color, stroke, cv2.LINE_AA)
  41.  
  42. img_item = "my-image.png"
  43. cv2.imwrite(img_item, frame)
  44. color = (0, 255, 0)
  45. stroke = 2
  46. end_cord_x = x + w
  47. end_cord_y = y + h
  48. cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
  49.  
  50. cv2.imshow('frame', frame)
  51. if nama == 'zboss':
  52. owner = nama
  53. tweet.posting_owner(owner)
  54. break
  55. elif nama == 'topik':
  56. owner = nama
  57. tweet.posting(owner)
  58. break
  59.  
  60. cv2.destroyWindow("frame")
  61. vc.release() #open webcam
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement