csharp 镜子亭中的面部情绪表达训练和分析

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp 镜子亭中的面部情绪表达训练和分析相关的知识,希望对你有一定的参考价值。

void FixedUpdate()
{
    // Send Point Data of User Face To Server.
    // Project Settings - Time - Fixed Timestep : 0.02
    if (!serverDebugging)
    {
        if (isOccupied && userTracking)
            this.gameObject.GetComponent<EmotionAnalysis>().SendFacePointData();       
    }

}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
[RequireComponent(typeof(AppManager))]
public class EmotionAnalysis : MonoBehaviour
{
    public SocketManager _SocketManager;
    public UpdateActionUnitData _UpdateActionUnitData;
    private double[] tempActionUnitStreamData;
    // Start is called before the first frame update
    void Start()
    {
        tempActionUnitStreamData = new double[_UpdateActionUnitData.actionUnitData.Length];
    }
    public void SendFacePointData()
    {
        // Sending face action unit data to server to analysis
        string rawStreamingData = "";
        for (int i = 0; i < _UpdateActionUnitData.actionUnitData.Length; i++)
        {
            tempActionUnitStreamData[i] = (double)_UpdateActionUnitData.actionUnitData[i];
            if (i == 0)
            {
                rawStreamingData = tempActionUnitStreamData[i].ToString();
            }
            else
            {
                rawStreamingData = rawStreamingData + "," + tempActionUnitStreamData[i];
            }
        }

        string streamingData = "[" + rawStreamingData + "]";
        _SocketManager.SendMessageToNode("face", streamingData);
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using LitJson;
using System.IO;

[RequireComponent(typeof(AppManager))]
public class EmotionTraining : MonoBehaviour
{
    public UpdateActionUnitData _UpdateActionUnitData;
    private string actionUnitsDataFileName = "ActionUnitsData.json";
    public int duration = 10;
    public int fps = 10;
    public List<string> recordedActionUnitData = new List<string>();
    public void RecordActionUnits(int index)
    {
        Debug.Log("Recording Started");
        StartCoroutine(_RecordActionUnits(index, duration, fps));
    }
    public IEnumerator _RecordActionUnits(int _index, int _duration, int _fps)
    {
        for (int frame = 0; frame < _duration * _fps; frame++)
        {
            string rawStreamingData = "";
            for (int i = 0; i < _UpdateActionUnitData.actionUnitData.Length; i++)
            {
                if (i == 0)
                {
                    rawStreamingData = ((double)_UpdateActionUnitData.actionUnitData[i]).ToString();
                }
                else
                {
                    rawStreamingData = rawStreamingData + "," + ((double)_UpdateActionUnitData.actionUnitData[i]).ToString();
                }
            }
            string recordedData = "[" + rawStreamingData + "," + _index + "]";
            recordedActionUnitData.Add(recordedData);
            yield return new WaitForSeconds(1 / _fps);
        }
        SaveRecordedData(_index, recordedActionUnitData);
        recordedActionUnitData.Clear();

    }
    void SaveRecordedData(int _index, List<string> ActionUnits)
    {
        JsonData actionUnitsJson = JsonMapper.ToJson(ActionUnits);
        string filePath = Path.Combine(Application.streamingAssetsPath, _index + "_" + actionUnitsDataFileName);
        File.WriteAllText(filePath, actionUnitsJson.ToString());
        Debug.Log("Recording Done");
        Debug.Log(_index + "_dataFile Saved :" + _index + "_" + actionUnitsDataFileName);
    }

}

以上是关于csharp 镜子亭中的面部情绪表达训练和分析的主要内容,如果未能解决你的问题,请参考以下文章

观色知喜怒:麻省理工成功开发情绪解读机器学习模型

面由心生,由脸观心:基于AI的面部微表情分析技术解读

面由心生,由脸观心:基于AI的面部微表情分析技术解读

情绪分析的训练数据[关闭]

实时面部表情分类(情绪)

令牌索引序列长度大于此模型的指定最大序列长度 (651 > 512),具有拥抱面部情感分类器