1. 面部检测画面反转映射关系
2. 点头动画打点错误
3. 位置检测增加移动距离检测
This commit is contained in:
terric 2023-11-29 17:59:42 +08:00
parent 43d9370d21
commit dcd855a087
5 changed files with 34 additions and 12 deletions

View File

@ -130054,11 +130054,11 @@ AnimationClip:
intParameter: 0 intParameter: 0
messageOptions: 0 messageOptions: 0
- time: 23.4 - time: 23.4
functionName: StartSampling functionName: EndSampling
data: data:
objectReferenceParameter: {fileID: 0} objectReferenceParameter: {fileID: 0}
floatParameter: 0 floatParameter: 0
intParameter: 2 intParameter: 12
messageOptions: 0 messageOptions: 0
- time: 23.9 - time: 23.9
functionName: PlayCountDownEndSE functionName: PlayCountDownEndSE

View File

@ -38,7 +38,7 @@ public class HoldPosition : PoseBase
LogPrint.Warning($"angle: {angle}", PrintLevel.Normal); LogPrint.Warning($"angle: {angle}", PrintLevel.Normal);
LogPrint.Log($"distance: {distance}, totalTimeSpan: {totalTimeSpan}", 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<Point> startPoint, List<Point> endPoint) public override Vector2 GetBasicVectorDirection(List<Point> startPoint, List<Point> endPoint)

View File

@ -286,28 +286,30 @@ public class YogaManager : MonoSingleton<YogaManager>
if (_baseNose == -Vector2.one) if (_baseNose == -Vector2.one)
return; return;
var angle = Mathf.Abs(Vector2.SignedAngle(Vector2.left, (nose - _baseNose))); 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) else if (_lastAction == AvatarAction.HeadTurnRight)
{ {
if (_baseNose == -Vector2.one) if (_baseNose == -Vector2.one)
return; return;
var angle = Mathf.Abs(Vector2.SignedAngle(Vector2.right, (nose - _baseNose))); 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) else if (_lastAction == AvatarAction.HeadTurnDown)
{ {
if (_baseNose == -Vector2.one) if (_baseNose == -Vector2.one)
return; return;
var angle = Mathf.Abs(Vector2.SignedAngle(Vector2.down, -(nose - _baseNose)));//坐标系起始点左上取y轴位移时需取反 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) else if (_lastAction == AvatarAction.HeadTurnUp)
{ {
if (_baseNose == -Vector2.one) if (_baseNose == -Vector2.one)
return; return;
var angle = Mathf.Abs(Vector2.SignedAngle(Vector2.up, -(nose - _baseNose))); //坐标系起始点左上取y轴位移时需取反 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) else if (_lastAction == AvatarAction.LeftLateralHead)
{ {

View File

@ -31,6 +31,9 @@ public class USBFaceDetectManager : FaceDetectManagerBase, IUVCDrawer
private void OnEnable() private void OnEnable()
{ {
//摄像头问题 需要反转
GlobalData.Instance.IsFlip = true;
mat4Display = new Mat(UVCManager.Instance.DefaultWidth, UVCManager.Instance.DefaultHeight, CvType.CV_8UC4); 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); 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); mat4DisplayTexture = new Mat(UVCManager.Instance.DefaultWidth, UVCManager.Instance.DefaultHeight, CvType.CV_8UC4);
@ -44,6 +47,9 @@ public class USBFaceDetectManager : FaceDetectManagerBase, IUVCDrawer
private void OnDisable() private void OnDisable()
{ {
//摄像头问题,需要反转
GlobalData.Instance.IsFlip = false;
Destroy(_videoTexture); Destroy(_videoTexture);
Destroy(_cutTexture); Destroy(_cutTexture);
_videoTexture = null; _videoTexture = null;
@ -93,7 +99,7 @@ public class USBFaceDetectManager : FaceDetectManagerBase, IUVCDrawer
RenderTexture.active = prevRT; RenderTexture.active = prevRT;
} }
private void textureToTargetPosTexture2DFlipped(Texture texture, Texture2D texture2D) private void textureToTargetPosTexture2D(Texture texture, Texture2D texture2D, bool isFlip)
{ {
if (texture == null) if (texture == null)
throw new ArgumentNullException("texture"); throw new ArgumentNullException("texture");
@ -110,8 +116,13 @@ public class USBFaceDetectManager : FaceDetectManagerBase, IUVCDrawer
RenderTexture prevRT = RenderTexture.active; RenderTexture prevRT = RenderTexture.active;
RenderTexture tempRT = RenderTexture.GetTemporary(texture.width, texture.height, 0, RenderTextureFormat.ARGB32); RenderTexture tempRT = RenderTexture.GetTemporary(texture.width, texture.height, 0, RenderTextureFormat.ARGB32);
if (isFlip)
Graphics.Blit(texture, tempRT, _flipImg); Graphics.Blit(texture, tempRT, _flipImg);
else
Graphics.Blit(texture, tempRT);
RenderTexture.active = tempRT; RenderTexture.active = tempRT;
texture2D.ReadPixels(new UnityEngine.Rect(PositionRect[0], PositionRect[1], PositionRect[2] - PositionRect[0], PositionRect[3] - PositionRect[1]), 0, 0, false); texture2D.ReadPixels(new UnityEngine.Rect(PositionRect[0], PositionRect[1], PositionRect[2] - PositionRect[0], PositionRect[3] - PositionRect[1]), 0, 0, false);
texture2D.Apply(false, false); texture2D.Apply(false, false);
@ -134,8 +145,17 @@ public class USBFaceDetectManager : FaceDetectManagerBase, IUVCDrawer
var devices = UVCManager.Instance.GetAttachedDevices(); var devices = UVCManager.Instance.GetAttachedDevices();
if (GlobalData.Instance.IsFlip)
{
textureToFlipTexture2D(devices.FirstOrDefault().previewTexture, _videoTexture); textureToFlipTexture2D(devices.FirstOrDefault().previewTexture, _videoTexture);
textureToTargetPosTexture2DFlipped(devices.FirstOrDefault().previewTexture, _cutTexture); 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(_videoTexture, mat4Display);
Utils.texture2DToMat(_cutTexture, mat4Process); Utils.texture2DToMat(_cutTexture, mat4Process);

View File

@ -23,7 +23,7 @@ public class RobotController : MonoBehaviour
var result = YogaManager.Instance.SamplingResult; var result = YogaManager.Instance.SamplingResult;
if (result != null && result == false) if (result != null && result == false)
{ {
AudioManager.Instance.PlayCVInQueue(action.ToString()); //AudioManager.Instance.PlayCVInQueue(action.ToString());
//AudioManager.Instance.PlayCVInQueue("And"); //AudioManager.Instance.PlayCVInQueue("And");
} }
else else