From dcd855a087c78fd53460f1b28a298a7ff682297c Mon Sep 17 00:00:00 2001 From: terric Date: Wed, 29 Nov 2023 17:59:42 +0800 Subject: [PATCH] bugfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 面部检测画面反转映射关系 2. 点头动画打点错误 3. 位置检测增加移动距离检测 --- Assets/Resources/Animation/Nod.anim | 4 +-- Assets/Scripts/PoseCheck/HoldPosition.cs | 2 +- Assets/Scripts/Service/YogaManager.cs | 10 ++++--- .../UI/Component/USBFaceDetectManager.cs | 28 ++++++++++++++++--- Assets/Scripts/UI/RobotController.cs | 2 +- 5 files changed, 34 insertions(+), 12 deletions(-) diff --git a/Assets/Resources/Animation/Nod.anim b/Assets/Resources/Animation/Nod.anim index 5c6daec..62ca8eb 100644 --- a/Assets/Resources/Animation/Nod.anim +++ b/Assets/Resources/Animation/Nod.anim @@ -130054,11 +130054,11 @@ AnimationClip: intParameter: 0 messageOptions: 0 - time: 23.4 - functionName: StartSampling + functionName: EndSampling data: objectReferenceParameter: {fileID: 0} floatParameter: 0 - intParameter: 2 + intParameter: 12 messageOptions: 0 - time: 23.9 functionName: PlayCountDownEndSE diff --git a/Assets/Scripts/PoseCheck/HoldPosition.cs b/Assets/Scripts/PoseCheck/HoldPosition.cs index 8a7dceb..d80d912 100644 --- a/Assets/Scripts/PoseCheck/HoldPosition.cs +++ b/Assets/Scripts/PoseCheck/HoldPosition.cs @@ -38,7 +38,7 @@ public class HoldPosition : PoseBase LogPrint.Warning($"angle: {angle}", PrintLevel.Normal); LogPrint.Log($"distance: {distance}, totalTimeSpan: {totalTimeSpan}", PrintLevel.Normal); - return (angle < 8 && (distance/ points.Count < 8f)); + return (angle < 8 && (distance/ points.Count < 12f)); } public override Vector2 GetBasicVectorDirection(List startPoint, List endPoint) diff --git a/Assets/Scripts/Service/YogaManager.cs b/Assets/Scripts/Service/YogaManager.cs index dc51b1b..5c6706b 100644 --- a/Assets/Scripts/Service/YogaManager.cs +++ b/Assets/Scripts/Service/YogaManager.cs @@ -286,28 +286,30 @@ public class YogaManager : MonoSingleton if (_baseNose == -Vector2.one) return; var angle = Mathf.Abs(Vector2.SignedAngle(Vector2.left, (nose - _baseNose))); - _samplingYogaResult = _samplingYogaResult.GetValueOrDefault() && (angle < 90); + _samplingYogaResult = _samplingYogaResult.GetValueOrDefault() && (angle < 90) && (nose - _baseNose).magnitude > 10; } else if (_lastAction == AvatarAction.HeadTurnRight) { if (_baseNose == -Vector2.one) return; var angle = Mathf.Abs(Vector2.SignedAngle(Vector2.right, (nose - _baseNose))); - _samplingYogaResult = _samplingYogaResult.GetValueOrDefault() && (angle < 90); + _samplingYogaResult = _samplingYogaResult.GetValueOrDefault() && (angle < 90) && (nose - _baseNose).magnitude > 10; } else if (_lastAction == AvatarAction.HeadTurnDown) { if (_baseNose == -Vector2.one) return; var angle = Mathf.Abs(Vector2.SignedAngle(Vector2.down, -(nose - _baseNose)));//坐标系起始点左上,取y轴位移时需取反 - _samplingYogaResult = _samplingYogaResult.GetValueOrDefault() && (angle < 90); + + LogPrint.Warning($"angle:{angle}, magnitude:{(nose - _baseNose).magnitude}", PrintLevel.Normal); + _samplingYogaResult = _samplingYogaResult.GetValueOrDefault() && (angle < 90) && (nose - _baseNose).magnitude > 10; } else if (_lastAction == AvatarAction.HeadTurnUp) { if (_baseNose == -Vector2.one) return; var angle = Mathf.Abs(Vector2.SignedAngle(Vector2.up, -(nose - _baseNose))); //坐标系起始点左上,取y轴位移时需取反 - _samplingYogaResult = _samplingYogaResult.GetValueOrDefault() && (angle < 90); + _samplingYogaResult = _samplingYogaResult.GetValueOrDefault() && (angle < 90) && (nose - _baseNose).magnitude > 10; } else if (_lastAction == AvatarAction.LeftLateralHead) { diff --git a/Assets/Scripts/UI/Component/USBFaceDetectManager.cs b/Assets/Scripts/UI/Component/USBFaceDetectManager.cs index 543df44..3784cf5 100644 --- a/Assets/Scripts/UI/Component/USBFaceDetectManager.cs +++ b/Assets/Scripts/UI/Component/USBFaceDetectManager.cs @@ -31,6 +31,9 @@ public class USBFaceDetectManager : FaceDetectManagerBase, IUVCDrawer private void OnEnable() { + //摄像头问题 需要反转 + GlobalData.Instance.IsFlip = true; + mat4Display = new Mat(UVCManager.Instance.DefaultWidth, UVCManager.Instance.DefaultHeight, CvType.CV_8UC4); mat4Process = new Mat(PositionRect[2] - PositionRect[0], PositionRect[3] - PositionRect[1], CvType.CV_8UC4); mat4DisplayTexture = new Mat(UVCManager.Instance.DefaultWidth, UVCManager.Instance.DefaultHeight, CvType.CV_8UC4); @@ -44,6 +47,9 @@ public class USBFaceDetectManager : FaceDetectManagerBase, IUVCDrawer private void OnDisable() { + //摄像头问题,需要反转 + GlobalData.Instance.IsFlip = false; + Destroy(_videoTexture); Destroy(_cutTexture); _videoTexture = null; @@ -93,7 +99,7 @@ public class USBFaceDetectManager : FaceDetectManagerBase, IUVCDrawer RenderTexture.active = prevRT; } - private void textureToTargetPosTexture2DFlipped(Texture texture, Texture2D texture2D) + private void textureToTargetPosTexture2D(Texture texture, Texture2D texture2D, bool isFlip) { if (texture == null) throw new ArgumentNullException("texture"); @@ -110,7 +116,12 @@ public class USBFaceDetectManager : FaceDetectManagerBase, IUVCDrawer RenderTexture prevRT = RenderTexture.active; RenderTexture tempRT = RenderTexture.GetTemporary(texture.width, texture.height, 0, RenderTextureFormat.ARGB32); - Graphics.Blit(texture, tempRT, _flipImg); + if (isFlip) + Graphics.Blit(texture, tempRT, _flipImg); + + else + Graphics.Blit(texture, tempRT); + RenderTexture.active = tempRT; texture2D.ReadPixels(new UnityEngine.Rect(PositionRect[0], PositionRect[1], PositionRect[2] - PositionRect[0], PositionRect[3] - PositionRect[1]), 0, 0, false); @@ -134,8 +145,17 @@ public class USBFaceDetectManager : FaceDetectManagerBase, IUVCDrawer var devices = UVCManager.Instance.GetAttachedDevices(); - textureToFlipTexture2D(devices.FirstOrDefault().previewTexture, _videoTexture); - textureToTargetPosTexture2DFlipped(devices.FirstOrDefault().previewTexture, _cutTexture); + if (GlobalData.Instance.IsFlip) + { + textureToFlipTexture2D(devices.FirstOrDefault().previewTexture, _videoTexture); + textureToTargetPosTexture2D(devices.FirstOrDefault().previewTexture, _cutTexture, true); + } + else + { + Utils.textureToTexture2D(devices.FirstOrDefault().previewTexture, _videoTexture); + textureToTargetPosTexture2D(devices.FirstOrDefault().previewTexture, _cutTexture, false); + } + Utils.texture2DToMat(_videoTexture, mat4Display); Utils.texture2DToMat(_cutTexture, mat4Process); diff --git a/Assets/Scripts/UI/RobotController.cs b/Assets/Scripts/UI/RobotController.cs index fbc723d..a5277dd 100644 --- a/Assets/Scripts/UI/RobotController.cs +++ b/Assets/Scripts/UI/RobotController.cs @@ -23,7 +23,7 @@ public class RobotController : MonoBehaviour var result = YogaManager.Instance.SamplingResult; if (result != null && result == false) { - AudioManager.Instance.PlayCVInQueue(action.ToString()); + //AudioManager.Instance.PlayCVInQueue(action.ToString()); //AudioManager.Instance.PlayCVInQueue("And"); } else