SHARE
TWEET

Untitled

a guest Mar 25th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import cv2
  2. import numpy
  3. class EyerisDetector:
  4.  
  5.     def __init__(self):
  6.         self.irises = []
  7.         self.blink_in_previous = False
  8.         self.blinks = 0
  9.         self.font=cv2.FONT_HERSHEY_SIMPLEX
  10.         self.eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
  11.     def run(self):
  12.         capture = cv2.VideoCapture(0)
  13.         k = cv2.waitKey(30) & 0xff
  14.         eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
  15.         while k != 27:  # ESC
  16.             ret,frame = capture.read()
  17.             gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  18.             self.irises=[]
  19.             eyes = self.eye_cascade.detectMultiScale(gray, 1.3, 5)
  20.             irises2 = []
  21.  
  22.             for (ex, ey, ew, eh) in eyes:
  23.                 iris_w = int(ex + float(ew / 2))
  24.                 iris_h = int(ey + float(eh / 2))
  25.                 irises2.append([numpy.float32(iris_w), numpy.float32(iris_h)])
  26.                 self.irises=numpy.array(irises2)
  27.             for w, h in self.irises:
  28.                 cv2.circle(frame, (w, h), 2, (0, 0, 255), 2)
  29.             cv2.imshow('Eyeris detector', frame)
  30.             k = cv2.waitKey(30) & 0xff
  31.             old_gray = gray.copy()
  32.         cv2.destroyAllWindows()
  33.  
  34. eyeris_detector = EyerisDetector()
  35. eyeris_detector.run()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top