This commit is contained in:
terric 2023-11-26 18:14:22 +08:00
parent fe78e3cbe8
commit b3d8d06b12
13 changed files with 64 additions and 29 deletions

View File

@ -214149,7 +214149,7 @@ AnimationClip:
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 3
intParameter: 2
messageOptions: 0
- time: 33.866665
functionName: ActionStart
@ -214205,7 +214205,7 @@ AnimationClip:
data:
objectReferenceParameter: {fileID: 0}
floatParameter: 0
intParameter: 3
intParameter: 2
messageOptions: 0
- time: 66.333336
functionName: FinishCurrentLevel

View File

@ -42,11 +42,13 @@ public class CVEstimator : Singleton<CVEstimator>
break;
}
YogaManager.Instance.CurrentEstimator.Init();
IsRunning = false;
LogPrint.Log("Current Estimator Inited", PrintLevel.Important);
//IsRunning = false;
_mainThread = new Thread(new ThreadStart(MainThread));
_mainThread.Start();
IsInited = true;
LogPrint.Log($"Inited:{IsInited}", PrintLevel.Important);
}
private void MainThread()
@ -75,9 +77,17 @@ public class CVEstimator : Singleton<CVEstimator>
LogPrint.Error($"Main Thread: {_mainThread.ThreadState}");
return;
}
_estimateThread.Start();
LogPrint.Log("EstimateThread Start");
IsRunning = true;
_estimateThread.Start();
}
public void StopEstimation()
{
if (IsRunning)
{
IsRunning = false;
}
Dispose();
}
public void Dispose()
@ -101,11 +111,11 @@ public class CVEstimator : Singleton<CVEstimator>
{
try
{
LogPrint.Log("Estimation Thread Running!IsRunning: " + IsRunning);
LogPrint.Log($"Estimation Thread Running!IsRunning:{IsRunning} {DateTime.Now}, {YogaManager.Instance.CurrentEstimator.GetType().FullName}", PrintLevel.Important);
Mat rgbaMat = YogaManager.Instance.RgbaMat;
if (rgbaMat == null)
{
LogPrint.Log("WebCamTexture is null. ");
LogPrint.Log("WebCamTexture is null. ", PrintLevel.Important);
LogPrint.Log("Re-Estimation.");
continue; //重新检测
}
@ -113,7 +123,7 @@ public class CVEstimator : Singleton<CVEstimator>
if (!YogaManager.Instance.CurrentEstimator.Esitmate(bgrMat, rgbaMat, out List<Point> points))
{
LogPrint.Log("Pose estimation failed. Re-Estimating.");
LogPrint.Log("Pose estimation failed. Re-Estimating.", PrintLevel.Important);
continue; //重新检测
}
@ -134,7 +144,7 @@ public class CVEstimator : Singleton<CVEstimator>
{
LogPrint.Exception(e);
}
}
bgrMat.Dispose();
}

View File

@ -38,7 +38,7 @@ public class HandsHold : PoseBase
}
var angle = Vector2.SignedAngle(Vector2.down, distance);
LogPrint.Log($"Angle:{angle}", PrintLevel.Normal);
if (MathF.Abs(angle) < 10)
if (MathF.Abs(angle) < 50 && distance.magnitude > 5f)
EventManager.Instance.Dispatch(YogaEventType.Action_Success); //方向不能偏移超过10°
else
{

View File

@ -39,7 +39,7 @@ public class HandsUp : PoseBase
}
var angle = Vector2.SignedAngle(Vector2.up, distance);
LogPrint.Log($"Angle:{angle}", PrintLevel.Normal);
if (MathF.Abs(angle) < 10)
if (MathF.Abs(angle) < 50 && distance.magnitude > 5f)
EventManager.Instance.Dispatch(YogaEventType.Action_Success); //方向不能偏移超过10°
else
{

View File

@ -27,10 +27,11 @@ public class HeadTurnDown : PoseBase
}
var angle = Vector2.SignedAngle(Vector2.down, distance);
LogPrint.Log($"Angle:{angle}", PrintLevel.Normal);
if (MathF.Abs(angle) < 10)
if (MathF.Abs(angle) < 50 && distance.magnitude > 5f)
EventManager.Instance.Dispatch(YogaEventType.Action_Success); //方向不能偏移超过10°
else
{
LogPrint.Warning($"Angle:{angle}, magnitude:{distance.magnitude}", PrintLevel.Important);
EventManager.Instance.Dispatch(YogaEventType.Action_Fail);
return;
}

View File

@ -29,7 +29,7 @@ public class HeadTurnLeft : PoseBase
var angle = Vector2.SignedAngle(Vector2.left, distance);
LogPrint.Log($"Angle:{angle}", PrintLevel.Normal);
if (MathF.Abs(angle) < 10)
if (MathF.Abs(angle) < 50 && distance.magnitude > 5f)
EventManager.Instance.Dispatch(YogaEventType.Action_Success); //方向不能偏移超过10°
else
{

View File

@ -29,7 +29,7 @@ public class HeadTurnRight : PoseBase
var angle = Vector2.SignedAngle(Vector2.right, distance);
LogPrint.Log($"Angle:{angle}", PrintLevel.Normal);
if (MathF.Abs(angle) < 10)
if (MathF.Abs(angle) < 50 && distance.magnitude > 5f)
EventManager.Instance.Dispatch(YogaEventType.Action_Success); //方向不能偏移超过10°
else
{

View File

@ -27,10 +27,11 @@ public class HeadTurnUp : PoseBase
}
var angle = Vector2.SignedAngle(Vector2.up, distance);
LogPrint.Log($"Angle:{angle}", PrintLevel.Normal);
if (MathF.Abs(angle) < 10)
if (MathF.Abs(angle) < 50 && distance.magnitude > 5f)
EventManager.Instance.Dispatch(YogaEventType.Action_Success); //方向不能偏移超过10°
else
{
LogPrint.Warning($"Angle:{angle}, magnitude:{distance.magnitude}", PrintLevel.Important);
EventManager.Instance.Dispatch(YogaEventType.Action_Fail);
return;
}

View File

@ -171,6 +171,7 @@ public class YogaManager : MonoSingleton<YogaManager>
//跳转到奖励界面
UIManager.Instance.CloseCurrent(); //关闭当前界面并停止检测
UIManager.Instance.ShowPanel<ClearingSettlementUI>(false, CurrentSuccessActionCount, MaxActionCount);//args[0] = successCount args[1] = totalCount
_estimateKeyPointsCache.Clear();
}
public void ScoreUpdate()
@ -259,7 +260,7 @@ public class YogaManager : MonoSingleton<YogaManager>
{
AvatarAction actionType = (AvatarAction)args.FirstOrDefault();
bool isMoveBack = (bool)args.LastOrDefault();
LogPrint.Log($"PlayGuideVoice: {actionType}", PrintLevel.Normal);
LogPrint.Log($"PlayGuideVoice: {actionType}");
if (isMoveBack)
{
AudioManager.Instance.PlayCVInQueue(actionType.ToString());
@ -299,7 +300,7 @@ public class YogaManager : MonoSingleton<YogaManager>
var startTime = ActionStartTime;
var endTime = DateTime.Now;
LogPrint.Log($"PlayGuideVoice: {actionType}", PrintLevel.Normal);
LogPrint.Log($"PlayGuideVoice: {actionType}");
if (isActionEnd)
{
AudioManager.Instance.PlayCVInQueue("End");

View File

@ -58,6 +58,7 @@ public partial class SROptions
{
var index = PlayerPrefs.GetInt("USBCameraIndex");
PlayerPrefs.SetInt("USBCameraIndex", ++index);
Debug.LogWarning("USBCameraIndex" + index);
}

View File

@ -1,7 +1,9 @@
using OpenCVForUnity.CoreModule;
using OpenCVForUnity.ImgprocModule;
using OpenCVForUnity.UnityUtils;
using Serenegiant.UVC;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
@ -14,8 +16,24 @@ namespace Yoga
protected Mat _bgrMat;
protected bool _isOnCamCapture = false;
protected Texture2D _displayTexture;
private bool _isInited;
public bool IsOnCamCapture { get => _isOnCamCapture; internal set => _isOnCamCapture = value; }
protected Texture2D DisplayTexture
{
get
{
if (_displayTexture == null)
{
_displayTexture = new Texture2D(UVCManager.Instance.DefaultWidth, UVCManager.Instance.DefaultHeight, TextureFormat.RGB24, false);
TargetDisplayer.texture = _displayTexture;
}
return _displayTexture;
}
set => _displayTexture = value;
}
private void Awake()
{
Init();
@ -23,6 +41,7 @@ namespace Yoga
public void Init()
{
_isInited = true;
Utils.setDebugMode(true); //打印日志
MatInitial();
CVEstimator.Instance.Init();//姿态检测模型初始化
@ -99,7 +118,7 @@ namespace Yoga
}
}
Utils.matToTexture2D(img, _displayTexture);
Utils.matToTexture2D(img, DisplayTexture);
}
private void OnDestroy()
@ -128,6 +147,7 @@ namespace Yoga
if (_bgrMat != null)
_bgrMat.Dispose();
CVEstimator.Instance.Dispose();
_isInited = false;
}
protected virtual void EventRegist()
{

View File

@ -33,7 +33,7 @@ namespace Yoga
{
Mat img = null;
LogPrint.Log("USB Camera!", PrintLevel.Normal);
LogPrint.Log("USB Camera!");
if (UVCManager.Instance != null &&
UVCManager.Instance.GetAttachedDevices() != null && UVCManager.Instance.GetAttachedDevices().Count > 0)
{
@ -41,19 +41,17 @@ namespace Yoga
for (int i = 0; i < devices.Count; i++)
{
UVCManager.CameraInfo device = devices[i];
LogPrint.Log($"id:{i},pid:{device.Pid},vid:{device.Vid},deviceName:{device.DeviceName}", PrintLevel.Normal);
LogPrint.Log($"id:{i},pid:{device.Pid},vid:{device.Vid},deviceName:{device.DeviceName}");
}
//var index = PlayerPrefs.GetInt("USBCameraIndex");
//if (index >= devices.Count || index < 0) //数量超出时候改为默认第一个
// index = 0;
var device1 = devices.Find(d => d.DeviceName.Equals("/dev/bus/usb/002/008"));
if (device1.previewTexture == null)
var index = PlayerPrefs.GetInt("USBCameraIndex");
if (index >= devices.Count || index < 0) //数量超出时候改为默认第一个
index = 0;
LogPrint.Log($"current ID {index} name:" + devices[index].DeviceName);
if (devices[index].previewTexture == null)
throw new Exception("No preview Texture found!");
var tmpTex = new Texture2D(UVCManager.Instance.DefaultWidth, UVCManager.Instance.DefaultHeight);
textureToFlipTexture2D(device1.previewTexture, tmpTex);
textureToFlipTexture2D(devices[index].previewTexture, tmpTex);
img = new Mat(UVCManager.Instance.DefaultHeight, UVCManager.Instance.DefaultWidth, CvType.CV_8UC3);
Utils.texture2DToMat(tmpTex, img);
}

View File

@ -498,6 +498,9 @@ namespace Serenegiant.UVC
{
//return FilterDevice(device.name);
if (device.name == "/dev/bus/usb/002/007")
return false;
if ((UVCDrawers == null) || (UVCDrawers.Length == 0))
{ // IUVCDrawerが割り当てられていないときはtrue(接続されたUVC機器を使用する)を返す
return true;