Exemplo n.º 1
0
input_face = camera_capture

gray, detface = smilerecognition.detect_face(input_face)
# detface jaa tyhjaksi () jos ei tunnista kasvoja

if len(detface)==1:
    #face_index = 0
    for face in detface:
        (x, y, w, h) = face
        if w > 100: #w pienenee kun etaisyys kamerasta kasvaa
            extracted_face = smilerecognition.extract_face_features(gray, face, (0.1, 0.05)) # (horiz,vert)
                                                                                         # (0.1, 0.05) => toimii!
                                                                                         # (0.15, 0.2) => antaa aina smile
                                                                                         # (0.03, 0.05) (0.075, 0.05)
                                                                                         # kts. extract_test.py kalibroimisesta
            prediction_result = smilerecognition.predict_face_is_smiling(extracted_face)
            #cv2.rectangle(input_face, (x, y), (x+w, y+h), (0, 255, 0), 2)
            #face_index += 1

    if prediction_result == 1:
        print "smile"
        #cv2.imshow("Smile", input_face)
    else:
        print "no smile"
        #cv2.imshow("No smile", input_face)    

    #cv2.waitKey(0)
else:
    print "Error: no face detected"
        retval, im = camera.read()
        return im
    for i in xrange(ramp_frames):
        temp = get_image()
    print("Taking image %s" % frameCount)
    camera_capture = get_image()
    del(camera)

    input_face = camera_capture
    gray, detface = smilerecognition.detect_face(input_face)
    if len(detface)==1:
        #face_index = 0
        for face in detface:
            (x, y, w, h) = face
            if w > 100: #w pienenee kun etaisyys kamerasta kasvaa
                extracted_face = smilerecognition.extract_face_features(gray, face, (0.1, 0.05))
                list.append(prediction_result, smilerecognition.predict_face_is_smiling(extracted_face))
                #face_index += 1

        if prediction_result[frameCount] == 1:
            print("Smile")
        else:
            print("No smile")

    else:
        list.append(prediction_result,[2])
        print("Error: no face detected")

    frameCount += 1
    time.sleep(1)