<jupyter_start><jupyter_text>在新的更新里，我删除了score以外的所有冗余的东西，使得下面的function只会输出0-100区间内的数字（我把倒数第5行的cv2.imshow()也去除了，即输出页面也不会展示图片组成的视频）。学生的初始分数为100分，每次出现注意力不集中的情况时会相应减去分数。1.打哈欠+闭眼 -52.打哈欠+睁眼 -43.不打哈欠+闭眼 -3与此同时，系统还会输出同学的实时状态。在倒数第四行，为文字输出。<jupyter_code>frameBuffer = []
BUFFER_AMOUNT = 20

def Drowsy_Studying():
    # initiate webcam
    eye = 0
    lip = 0
    cap = cv2.VideoCapture(0)

    w = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
    h = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
    print(cap.get(cv2.CAP_PROP_FPS))


    if not cap.isOpened():
        raise IOError('Cannot open webcam')

    # set a counter

    counter = 0

    # create a while loop that runs while webcam is in use

    while True:

        # capture frames being outputted by webcam

        ret, _frame = cap.read()
        cv2.imshow("new",_frame)
        # use only every other frame to manage speed and memory usage

        frameBuffer.append(_frame)
        if len(frameBuffer) < BUFFER_AMOUNT:
            print("pending")
            continue
        
        score = 100
        # function called on the frame
        for frame in frameBuffer:    
            try:
                image_for_prediction = eye_cropper(frame)
                image_for_prediction_lip = lip_cropper(frame)
                image_for_prediction = np.array(image_for_prediction)
                image_for_prediction = np.expand_dims(image_for_prediction, axis=0)
                image_for_prediction_lip = np.array(image_for_prediction_lip)
                image_for_prediction_lip = np.expand_dims(image_for_prediction_lip, axis=0)
                prediction = eye_model.predict(image_for_prediction)
                prediction_lip = lip_model.predict(image_for_prediction_lip)
                prediction = np.argmax(prediction[0], axis=0)
                prediction_lip = np.argmax(prediction_lip[0], axis=0)
            except:
                print("faild to estimate")
                continue


            if prediction == 1:
                eye = eye + 1
            else: 
                eye = 0
            if prediction_lip == 1:
                lip = lip + 1
            else: 
                lip = 0
            # Based on prediction, display either "Open Eyes" or "Closed Eyes"
            try:
                if lip <2 and eye < 5:
                    counter = 0
                    status = 'No_Yawn + Eye_Open'
                    score -= 0.1
                elif lip > 2 and eye > 5:
                    counter = counter + 1
                    status = 'Yawn + Eye_closed'
                    score -= 5
                elif lip < 2 and eye > 5:
                    counter = counter + 1
                    status = 'No_Yawn + Eye_closed'
                    score -= 3
                else: 
                    counter = counter + 1
                    status = 'Yawn + Eye_Open'
                    score -= 4

            except:
                continue
            
            
            k = cv2.waitKey(1)
            if k == 27:
                break
        #cv2.imshow('Drowsiness Detection', frame)
        print("The student is {0}".format(status))
        print("Score is {0}".format(score))
    cap.release()
    cv2.destroyAllWindows()



Drowsy_Studying()

a = []

for i in range(100):
    a.append(i)
    if len (a)< 20:
        continue
    print(a)
    a.clear()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08330871491875923, 'fraction_numerical': 0.020384047267355983, 'mean_word_length': 1.5554716981132075, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '403869', 'license': 'MIT', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1109, 'n_words': 227, 'path': 'DetectionSource/camera_v2.ipynb', 'repo_name': 'OuNiSang/ELEC490Project', 'size': '3385'}