As stated, to achieve a simple opened and closed in accordance with a frame detection camera function.
The initial idea is:
1. cv2 calling computer camera, reads a picture frame.
2. The screen as Hal - an input interface face classifier, the classifier according to the result returned results of the classification region.
3. Results cropped area of the image, as Hal - eye classifier inputs.
4. If the image on the output face classifier can not detect the eye classifier i.e. closed-eye state is confirmed and give tips.
During operation substantially clear.
Put the code:
# - * - Coding: UTF-. 8 - * - from __future__ Import unicode_literals Import CV2 AS CV # Import Time # Hal cascade classifier FD = cv.CascadeClassifier (R & lt ' C: \ the Users \ wenzhe.tian \ Desktop \ closed identifying eye \ haarcascade_frontalface_alt.xml ' ) ED = cv.CascadeClassifier (R & lt ' C: \ the Users \ wenzhe.tian \ Desktop \ closed eye recognition \ haarcascade_eye_tree_eyeglasses.xml ' ) # Nd = cv.CascadeClassifier (' ../../ Data / Haar / nose.xml ') VC = cv.VideoCapture (0) the while True: Frame = vc.read () [. 1 ] Faces= fd.detectMultiScale(frame, 1.3, 5) for l, t, w, h in faces: a, b = int(w / 2), int(h / 2) cv.ellipse(frame, (l+a, t+b), (a, b), 0, 0, 360, (255, 0, 255), 2) face = frame[t:t+h, l:l+w] eyes = ed.detectMultiScale(face, 1.3, 5) for l, t, w, h in eyes: a, b = int(w / 2), int(h / 2) cv.ellipse(face, (l+a, t+b), (a, b), 0,0, 360, (0, 255, 0), 2) # noses = nd.detectMultiScale(face, 1.3, 5) # for l, t, w, h in noses: # a, b = int(w / 2), int(h / 2) # cv.ellipse(face, (l a, t b), (a, b), 0, # 0, 360, (255, 0, 0), 2) # a = 'close eyes!!' if len(eyes) != 0: cv.destroyWindow('close eyes!!') # cv.moveWindow('open eyes',300,300) cv.imshow('open eyes!!', frame) else: cv.destroyWindow('open eyes!!') # time.sleep(1) # cv.moveWindow('close eyes',300,300) cv.imshow('close eyes!!', frame) if cv.waitKey(1) == ord(' '): break vc.release() cv.destroyAllWindows()