2023-11-15 08:10:56 +00:00
|
|
|
|
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()
|
|
|
|
|
{
|
2023-11-17 06:44:27 +00:00
|
|
|
|
|
2023-11-15 08:10:56 +00:00
|
|
|
|
|
|
|
|
|
InitModel();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract void InitModel();
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
DisposeModel();
|
|
|
|
|
}
|
|
|
|
|
public abstract void DisposeModel();
|
|
|
|
|
|
2023-11-17 06:44:27 +00:00
|
|
|
|
public abstract bool Esitmate(Mat bgrMat, Mat rgbaMat, out List<Point> points);
|
2023-11-15 08:10:56 +00:00
|
|
|
|
|
|
|
|
|
protected bool IsObjectValid(float[] box, float[] confidence, float[] classID, Mat rgbaMat)
|
|
|
|
|
{
|
2023-11-21 10:28:27 +00:00
|
|
|
|
if ((int)classID[0] != 0 || confidence[0] < 0.6f) //只检测人体,且置信度大于60%
|
2023-11-15 08:10:56 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
//是否满足主驾/副驾的位置条件
|
|
|
|
|
float width = rgbaMat.width();
|
|
|
|
|
//获取矩形的中点
|
|
|
|
|
float centerX = (box[0] + box[2]) / 2;
|
|
|
|
|
//左边副驾驶,右边主驾驶
|
2023-11-21 10:28:27 +00:00
|
|
|
|
if (centerX < width / 2) //主驾驶
|
|
|
|
|
{
|
|
|
|
|
//选择为副驾驶,返回false
|
2023-11-27 05:49:53 +00:00
|
|
|
|
if (!GlobalData.Instance.IsDriverPosition)
|
2023-11-21 10:28:27 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else //副驾驶
|
|
|
|
|
{
|
|
|
|
|
//选择为主驾驶,返回false
|
2023-11-27 05:49:53 +00:00
|
|
|
|
if (GlobalData.Instance.IsDriverPosition)
|
2023-11-21 10:28:27 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-11-15 08:10:56 +00:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-24 12:04:16 +00:00
|
|
|
|
public abstract void DebugPrint(ref Mat img, bool isRGB = false);
|
2023-11-15 08:10:56 +00:00
|
|
|
|
|
2023-11-24 18:39:53 +00:00
|
|
|
|
public virtual bool Check(ref Mat img) { return true; }
|
2023-11-15 08:10:56 +00:00
|
|
|
|
}
|