新增主副驾区别功能,新增选取最大区块功能(openpose)
This commit is contained in:
parent
687ddbd876
commit
cefaba5dea
|
@ -449,7 +449,8 @@ MonoBehaviour:
|
|||
m_RequiresDepthTextureOption: 2
|
||||
m_RequiresOpaqueTextureOption: 2
|
||||
m_CameraType: 0
|
||||
m_Cameras: []
|
||||
m_Cameras:
|
||||
- {fileID: 1969623179}
|
||||
m_RendererIndex: -1
|
||||
m_VolumeLayerMask:
|
||||
serializedVersion: 2
|
||||
|
@ -784,7 +785,7 @@ GameObject:
|
|||
m_Icon: {fileID: 0}
|
||||
m_NavMeshLayer: 0
|
||||
m_StaticEditorFlags: 0
|
||||
m_IsActive: 0
|
||||
m_IsActive: 1
|
||||
--- !u!114 &1969623177
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
public class GlobalData : MonoSingleton<GlobalData>
|
||||
{
|
||||
private PositionType position = PositionType.None;
|
||||
|
||||
public PositionType Position { get => position; internal set => position = value; }
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a40cd440bbfea884b978d45f27249385
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -29,7 +29,7 @@ public abstract class Estimator
|
|||
|
||||
protected bool IsObjectValid(float[] box, float[] confidence, float[] classID, Mat rgbaMat)
|
||||
{
|
||||
if ((int)classID[0] != 0 || confidence[0] < 0.8f) //只检测人体,且置信度大于80%
|
||||
if ((int)classID[0] != 0 || confidence[0] < 0.6f) //只检测人体,且置信度大于60%
|
||||
return false;
|
||||
|
||||
//是否满足主驾/副驾的位置条件
|
||||
|
@ -37,6 +37,18 @@ public abstract class Estimator
|
|||
//获取矩形的中点
|
||||
float centerX = (box[0] + box[2]) / 2;
|
||||
//左边副驾驶,右边主驾驶
|
||||
if (centerX < width / 2) //主驾驶
|
||||
{
|
||||
//选择为副驾驶,返回false
|
||||
if (GlobalData.Instance.Position == PositionType.CoDriver)
|
||||
return false;
|
||||
}
|
||||
else //副驾驶
|
||||
{
|
||||
//选择为主驾驶,返回false
|
||||
if (GlobalData.Instance.Position == PositionType.Driver)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -51,10 +51,8 @@ public class MediaPipeEstimator : Estimator
|
|||
points = null;
|
||||
Mat result = _personDetector.infer(bgrMat);
|
||||
|
||||
if (result.rows() == 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (result.rows() == 0)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < result.rows(); ++i)
|
||||
{
|
||||
|
@ -101,13 +99,10 @@ public class MediaPipeEstimator : Estimator
|
|||
float[] landmarks_presence = new float[(39 - auxiliary_points_num)];
|
||||
results_col4_199_39x5.colRange(new OpenCVRange(4, 5)).get(0, 0, landmarks_presence);
|
||||
|
||||
|
||||
Mat results_col199_316_39x3 = result.rowRange(new OpenCVRange(199, 316 - (3 * auxiliary_points_num))).reshape(1, 39 - auxiliary_points_num);
|
||||
float[] landmarks_world = new float[(39 - auxiliary_points_num) * 3];
|
||||
results_col199_316_39x3.get(0, 0, landmarks_world);
|
||||
|
||||
|
||||
|
||||
//将关键点映射到现有的open pose关键点上
|
||||
retVal.Add(GetPointData(landmarks_screen_xy, landmarks_presence, 0)); //Nose
|
||||
retVal.Add(new Point(-1, -1)); //Neck
|
||||
|
|
|
@ -5,6 +5,7 @@ using OpenCVForUnity.UnityUtils;
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
using Yoga;
|
||||
|
||||
public class OpenPoseEsimater : Estimator
|
||||
|
@ -62,6 +63,7 @@ public class OpenPoseEsimater : Estimator
|
|||
var voloResultBox = new List<float[]>();
|
||||
|
||||
bool hasValidObject = false;
|
||||
List<List<float[]>> boxList = new();
|
||||
|
||||
for (int i = results.rows() - 1; i >= 0; --i)
|
||||
{
|
||||
|
@ -72,18 +74,33 @@ public class OpenPoseEsimater : Estimator
|
|||
float[] cls = new float[1];
|
||||
results.get(i, 5, cls); //类别
|
||||
|
||||
if (!IsObjectValid(box, conf, cls, rgbaMat))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!IsObjectValid(box, conf, cls, rgbaMat)) //不符合规则的,跳过
|
||||
continue;
|
||||
|
||||
hasValidObject = true;
|
||||
voloResultBox.Clear();
|
||||
voloResultBox.Add(box);
|
||||
voloResultBox.Add(conf);
|
||||
voloResultBox.Add(cls);
|
||||
break;
|
||||
List<float[]> item= new List<float[]>();
|
||||
item.Add(box);
|
||||
item.Add(conf);
|
||||
item.Add(cls);
|
||||
boxList.Add(item);
|
||||
}
|
||||
|
||||
float area = 0;
|
||||
List<float[]> maxSizeBox = new List<float[]>();
|
||||
//选择最大的一个
|
||||
foreach(var box in boxList)
|
||||
{
|
||||
var rect = box[0];
|
||||
var tmp = (rect[2] - rect[0]) * (rect[3] - rect[1]);
|
||||
area = Math.Max(area, tmp);
|
||||
if (area == tmp)
|
||||
{
|
||||
maxSizeBox = box;
|
||||
}
|
||||
}
|
||||
voloResultBox.Clear();
|
||||
voloResultBox = maxSizeBox;
|
||||
|
||||
if (!hasValidObject) //没有检测到人体
|
||||
{
|
||||
Debug.Log("No person block found. Re-Estimation.");
|
||||
|
|
|
@ -33,11 +33,20 @@ public class MainUIPanel : UIPanelBase
|
|||
|
||||
public void OnDriverBtnClicked()
|
||||
{
|
||||
GlobalData.Instance.Position = PositionType.Driver;
|
||||
UIManager.Instance.ShowPanel<ActionListUIPanel>(true);
|
||||
}
|
||||
|
||||
public void OnCoDriverBtnClicked()
|
||||
{
|
||||
GlobalData.Instance.Position = PositionType.CoDriver;
|
||||
UIManager.Instance.ShowPanel<ActionListUIPanel>(true);
|
||||
}
|
||||
}
|
||||
|
||||
public enum PositionType
|
||||
{
|
||||
None,
|
||||
Driver,
|
||||
CoDriver
|
||||
}
|
|
@ -14,11 +14,11 @@ public class YogaDataLoader
|
|||
data[-1] = new YogaData()
|
||||
{
|
||||
VideoPath = "Video/Action3",
|
||||
Action = AvatarAction.HandsUp,
|
||||
ModelType = ModelType.MediapipePose,
|
||||
Action = AvatarAction.HeadShake,
|
||||
ModelType = ModelType.OpenPose,
|
||||
MaxActionCount = 1000,
|
||||
TotalSeconds = 20.0f,
|
||||
MustPoints = new List<string>() { "Nose", "RShoulder", "LShoulder", "RElbow", "LElbow" },
|
||||
MustPoints = new List<string>() { "Nose", "REye", "LEye", "Neck" },
|
||||
//AnyPoints = new List<string>() { "RWrist", "LWrist" }
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue