@@ -0,0 +1,2216 @@
+%22%22%22Detect emotion from webacam stream.%22%22%22%0Aimport time%0A%0Aimport cv2%0Aimport dlib%0Aimport imutils%0Afrom imutils.video import VideoStream%0Afrom imutils import face_utils%0A%0Afrom sklearn.externals import joblib%0A# from sklearn.svm import SVC%0A%0Afrom featuregen import features_from_shape%0A%0A%0Aif __name__ == '__main__':%0A    # emotion list%0A    EMOTIONS = %5B%22anger%22,%0A                %22disgust%22,%0A                %22fear%22,%0A                %22happy%22,%0A                %22neutral%22,%0A                %22sadness%22,%0A                %22surprise%22%5D%0A    # detector%0A    DETECTOR = dlib.get_frontal_face_detector()%0A    # predictor%0A    PREDICTOR = dlib.shape_predictor(%22shape_predictor_68_face_landmarks.dat%22)%0A    # classifier%0A    CLASSIFIER = joblib.load('classifier.pkl')%0A%0A    # initialize the video stream and allow the cammera sensor to warmup%0A    print(%22%5BINFO%5D camera sensor warming up...%22)%0A%0A    VIDEOSTREAM = VideoStream(framerate=4).start()%0A    time.sleep(2.0)%0A%0A    EMOTION = 0%0A%0A    # counter = 0%0A%0A    # loop over the frames from the video stream%0A    while True:%0A        # grab the frame from the threaded video stream, resize it to%0A        # have a maximum width of 400 pixels, and convert it to%0A        # grayscale%0A        FRAME = VIDEOSTREAM.read()%0A        FRAME = imutils.resize(FRAME, width=400)%0A        GRAY = cv2.cvtColor(FRAME, cv2.COLOR_BGR2GRAY)%0A        # detect faces in the grayscale frame%0A        RECTS = DETECTOR(GRAY, 0)%0A%0A        # loop over the face detections%0A        for rect in RECTS:%0A            shape = PREDICTOR(GRAY, rect)%0A            vector = features_from_shape(shape)%0A            EMOTION = CLASSIFIER.predict(%5Bvector%5D)%5B0%5D%0A%0A            shape = face_utils.shape_to_np(shape)%0A            # loop over the (x, y)-coordinates for the facial landmarks%0A            # and draw them on the image%0A            for (x, y) in shape:%0A                cv2.circle(FRAME, (x, y), 1, (0, 0, 255), -1)%0A        # show the frame%0A        cv2.putText(FRAME,%0A                    EMOTIONS%5BEMOTION%5D,%0A                    (5,20), cv2.FONT_HERSHEY_SIMPLEX, 1, 255)%0A%0A        cv2.imshow(%22Frame%22, FRAME)%0A%0A        KEY = cv2.waitKey(1) & 0xFF%0A        if KEY == ord(%22q%22):%0A            break%0A%0A    # do a bit of cleanup%0A    cv2.destroyAllWindows()%0A    VIDEOSTREAM.stop()%0A

Recognize emotion from webcam stream