Health/Assets/Scripts/PoseCheck/EstimateModel/Estimator.cs

60 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using OpenCVForUnity.CoreModule;
using OpenCVForUnity.ImgprocModule;
using OpenCVForUnity.UnityUtils;
using OpenCVForUnity.UnityUtils.Helper;
using System;
using System.Collections.Generic;
using UnityEngine;
using Yoga;
public abstract class Estimator
{
//初始化
public void Init()
{
InitModel();
}
public abstract void InitModel();
public void Dispose()
{
DisposeModel();
}
public abstract void DisposeModel();
public abstract bool Esitmate(Mat bgrMat, Mat rgbaMat, out List<Point> points);
protected bool IsObjectValid(float[] box, float[] confidence, float[] classID, Mat rgbaMat)
{
if ((int)classID[0] != 0 || confidence[0] < 0.6f) //只检测人体且置信度大于60%
return false;
//是否满足主驾/副驾的位置条件
float width = rgbaMat.width();
//获取矩形的中点
float centerX = (box[0] + box[2]) / 2;
//左边副驾驶,右边主驾驶
if (centerX < width / 2) //主驾驶
{
//选择为副驾驶返回false
if (!GlobalData.Instance.IsDriverPosition)
return false;
}
else //副驾驶
{
//选择为主驾驶返回false
if (GlobalData.Instance.IsDriverPosition)
return false;
}
return true;
}
public abstract void DebugPrint(ref Mat img, bool isRGB = false);
public virtual bool Check(ref Mat img) { return true; }
}