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 镜子亭中的面部情绪表达训练和分析的主要内容,如果未能解决你的问题,请参考以下文章