From b3d8d06b12afd7c8edb1f25e02a1a8688bd5b673 Mon Sep 17 00:00:00 2001 From: terric Date: Sun, 26 Nov 2023 18:14:22 +0800 Subject: [PATCH] bugfix --- Assets/Resources/Animation/Nod.anim | 4 +-- .../PoseCheck/EstimateModel/CVEstimator.cs | 26 +++++++++++++------ Assets/Scripts/PoseCheck/HandsHold.cs | 2 +- Assets/Scripts/PoseCheck/HandsUp.cs | 2 +- Assets/Scripts/PoseCheck/HeadTurnDown.cs | 3 ++- Assets/Scripts/PoseCheck/HeadTurnLeft.cs | 2 +- Assets/Scripts/PoseCheck/HeadTurnRight.cs | 2 +- Assets/Scripts/PoseCheck/HeadTurnUp.cs | 3 ++- Assets/Scripts/Service/YogaManager.cs | 5 ++-- Assets/Scripts/Tool/DebuggerOptions.cs | 1 + .../UI/Component/CaptureManagerBase.cs | 22 +++++++++++++++- .../MotionUSBCameraCaptureManager.cs | 18 ++++++------- .../Scripts/UVCManager.cs | 3 +++ 13 files changed, 64 insertions(+), 29 deletions(-) diff --git a/Assets/Resources/Animation/Nod.anim b/Assets/Resources/Animation/Nod.anim index 60eaee6..d71c7a4 100644 --- a/Assets/Resources/Animation/Nod.anim +++ b/Assets/Resources/Animation/Nod.anim @@ -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 diff --git a/Assets/Scripts/PoseCheck/EstimateModel/CVEstimator.cs b/Assets/Scripts/PoseCheck/EstimateModel/CVEstimator.cs index 4c07222..d81ac00 100644 --- a/Assets/Scripts/PoseCheck/EstimateModel/CVEstimator.cs +++ b/Assets/Scripts/PoseCheck/EstimateModel/CVEstimator.cs @@ -42,11 +42,13 @@ public class CVEstimator : Singleton 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 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 { 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 if (!YogaManager.Instance.CurrentEstimator.Esitmate(bgrMat, rgbaMat, out List 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 { LogPrint.Exception(e); } - + } bgrMat.Dispose(); } diff --git a/Assets/Scripts/PoseCheck/HandsHold.cs b/Assets/Scripts/PoseCheck/HandsHold.cs index 4a8ae48..1709011 100644 --- a/Assets/Scripts/PoseCheck/HandsHold.cs +++ b/Assets/Scripts/PoseCheck/HandsHold.cs @@ -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 { diff --git a/Assets/Scripts/PoseCheck/HandsUp.cs b/Assets/Scripts/PoseCheck/HandsUp.cs index fe3e91a..8dca79d 100644 --- a/Assets/Scripts/PoseCheck/HandsUp.cs +++ b/Assets/Scripts/PoseCheck/HandsUp.cs @@ -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 { diff --git a/Assets/Scripts/PoseCheck/HeadTurnDown.cs b/Assets/Scripts/PoseCheck/HeadTurnDown.cs index d2f79f2..f54d09b 100644 --- a/Assets/Scripts/PoseCheck/HeadTurnDown.cs +++ b/Assets/Scripts/PoseCheck/HeadTurnDown.cs @@ -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; } diff --git a/Assets/Scripts/PoseCheck/HeadTurnLeft.cs b/Assets/Scripts/PoseCheck/HeadTurnLeft.cs index 2e58a68..9deec22 100644 --- a/Assets/Scripts/PoseCheck/HeadTurnLeft.cs +++ b/Assets/Scripts/PoseCheck/HeadTurnLeft.cs @@ -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 { diff --git a/Assets/Scripts/PoseCheck/HeadTurnRight.cs b/Assets/Scripts/PoseCheck/HeadTurnRight.cs index 1760b34..803e596 100644 --- a/Assets/Scripts/PoseCheck/HeadTurnRight.cs +++ b/Assets/Scripts/PoseCheck/HeadTurnRight.cs @@ -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 { diff --git a/Assets/Scripts/PoseCheck/HeadTurnUp.cs b/Assets/Scripts/PoseCheck/HeadTurnUp.cs index b194a49..dec9d40 100644 --- a/Assets/Scripts/PoseCheck/HeadTurnUp.cs +++ b/Assets/Scripts/PoseCheck/HeadTurnUp.cs @@ -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; } diff --git a/Assets/Scripts/Service/YogaManager.cs b/Assets/Scripts/Service/YogaManager.cs index d140dd9..c790cab 100644 --- a/Assets/Scripts/Service/YogaManager.cs +++ b/Assets/Scripts/Service/YogaManager.cs @@ -171,6 +171,7 @@ public class YogaManager : MonoSingleton //跳转到奖励界面 UIManager.Instance.CloseCurrent(); //关闭当前界面并停止检测 UIManager.Instance.ShowPanel(false, CurrentSuccessActionCount, MaxActionCount);//args[0] = successCount args[1] = totalCount + _estimateKeyPointsCache.Clear(); } public void ScoreUpdate() @@ -259,7 +260,7 @@ public class YogaManager : MonoSingleton { 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 var startTime = ActionStartTime; var endTime = DateTime.Now; - LogPrint.Log($"PlayGuideVoice: {actionType}", PrintLevel.Normal); + LogPrint.Log($"PlayGuideVoice: {actionType}"); if (isActionEnd) { AudioManager.Instance.PlayCVInQueue("End"); diff --git a/Assets/Scripts/Tool/DebuggerOptions.cs b/Assets/Scripts/Tool/DebuggerOptions.cs index 973401a..2d804be 100644 --- a/Assets/Scripts/Tool/DebuggerOptions.cs +++ b/Assets/Scripts/Tool/DebuggerOptions.cs @@ -58,6 +58,7 @@ public partial class SROptions { var index = PlayerPrefs.GetInt("USBCameraIndex"); PlayerPrefs.SetInt("USBCameraIndex", ++index); + Debug.LogWarning("USBCameraIndex" + index); } diff --git a/Assets/Scripts/UI/Component/CaptureManagerBase.cs b/Assets/Scripts/UI/Component/CaptureManagerBase.cs index e82917b..1fb506b 100644 --- a/Assets/Scripts/UI/Component/CaptureManagerBase.cs +++ b/Assets/Scripts/UI/Component/CaptureManagerBase.cs @@ -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() { diff --git a/Assets/Scripts/UI/Component/MotionUSBCameraCaptureManager.cs b/Assets/Scripts/UI/Component/MotionUSBCameraCaptureManager.cs index 9292459..32891bb 100644 --- a/Assets/Scripts/UI/Component/MotionUSBCameraCaptureManager.cs +++ b/Assets/Scripts/UI/Component/MotionUSBCameraCaptureManager.cs @@ -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); } diff --git a/Assets/UVC4UnityAndroidPlugin/Scripts/UVCManager.cs b/Assets/UVC4UnityAndroidPlugin/Scripts/UVCManager.cs index ee305c1..0f34c2e 100644 --- a/Assets/UVC4UnityAndroidPlugin/Scripts/UVCManager.cs +++ b/Assets/UVC4UnityAndroidPlugin/Scripts/UVCManager.cs @@ -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;