使用scikit-learn和OpenCV检测情绪时的结果波动

我正在尝试建立一个非常基本的情绪检测系统(快乐或不快乐),我已经在图像数据集(sklearn.datasets.fetch_olivetti_faces)上训练了我的模型(来自sklearn.neural_network的MLPClassifier)。

我的程序打开实时摄像机供稿,然后检测到脸部,并在脸部周围画一个圆圈。提取面部并将其展平,然后将数据提供给分类器。 分类器预测快乐或不快乐,然后将文本放在圆圈附近。

但是,当我尝试检测面孔并从实时供稿中对它们进行分类时,结果似乎波动很大,就像在快乐与不快乐之间闪烁一样。我的代码看起来像这样


while True:


    #Reading frame
    _,img = cap.read()


    #Mirror effect
    img = cv2.flip(img,1)

    #converting to grayscale
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

    #detecting face(s)
    faces = face_cascade.detectMultiScale(gray,1.6,3,minSize=(60,60))

    #if faces are found
    if(len(faces)):

        #for (x,y) and (w,h) of each face found
        for(x,y,w,h) in faces:

                    #finding center of the face
                    x_c = x+w//2;
                    y_c = y+h//2;

                    #finding radius of the circle 
                    radius = int(math.sqrt( (x-x_c)**2 + (y-y_c)**2 ))

                    #drawing the circle
                    cv2.circle(img,(x_c,y_c),radius,(255,255,255),1)

                    #cropping the face to extract it
                    crop_face = gray[y:y+h,x:x+w]



        #resizing it so that it can be fed to the algorithm
        crop_face = cv2.resize(crop_face,(64,64),interpolation = cv2.INTER_LINEAR)

        #flattening for the same reason
        crop_face = crop_face.flatten()

        #predicting and mapping the emotion (target = ['happy','not happy'])
        prediction = target[int(model.predict(crop_face.reshape(1,-1)))]

        #Displaying the predicted emotion
        cv2.putText(img,prediction,(x,y-(y-h)),cv2.FONT_HERSHEY_SIMPLEX,1,(0,0),2)

    cv2.imshow('Frame',img)

我如何使结果不以闪烁的方式(相机Feed上的文字)出现而平滑地显示(没有波动)

除了再次预处理数据外,任何建议都将有所帮助。

谢谢。

daguai123456 回答:使用scikit-learn和OpenCV检测情绪时的结果波动

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3116633.html

大家都在问