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 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; } }