|
@ -10,9 +10,9 @@ public abstract class MarkSearcherBase |
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 当前相机参数信息
|
|
|
/// 当前相机参数信息
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
protected CameraCalcInfo CameraCalcInfo { get; set; } |
|
|
protected CameraCalcInfo _cameraCalcInfo { get; set; } |
|
|
|
|
|
|
|
|
protected List<MarkLabelCalcInfo> MarkLabelInfoList { get; set; } = new(); |
|
|
protected List<MarkLabelCalcInfo> _markLabelInfoList { get; set; } = new(); |
|
|
|
|
|
|
|
|
protected MatrixBuilder<double> MBuilder { get; set; } = Matrix<double>.Build; |
|
|
protected MatrixBuilder<double> MBuilder { get; set; } = Matrix<double>.Build; |
|
|
|
|
|
|
|
@ -25,14 +25,7 @@ public abstract class MarkSearcherBase |
|
|
|
|
|
|
|
|
public MarkSearcherBase(CameraCalcInfo cameraCalcInfo) |
|
|
public MarkSearcherBase(CameraCalcInfo cameraCalcInfo) |
|
|
{ |
|
|
{ |
|
|
InitCameraCalcInfoRelated(cameraCalcInfo); |
|
|
UpdateCameraCalcInfoRelated(cameraCalcInfo); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void InitCameraCalcInfoRelated(CameraCalcInfo cameraCalcInfo) |
|
|
|
|
|
{ |
|
|
|
|
|
CameraCalcInfo = cameraCalcInfo; |
|
|
|
|
|
CalcSensor(); |
|
|
|
|
|
World2CameraMatrix = ConvertWorldToCamera(cameraCalcInfo); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#region Calc
|
|
|
#region Calc
|
|
@ -41,23 +34,20 @@ public abstract class MarkSearcherBase |
|
|
/// 计算标签位置过程
|
|
|
/// 计算标签位置过程
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
public void Calc(CameraCalcInfo cameraCalcInfo) |
|
|
public List<MarkLabelCalcResult> Calc() |
|
|
{ |
|
|
{ |
|
|
//判断
|
|
|
List<MarkLabelCalcResult> resultList = new(); |
|
|
if (IsCameraRotate(cameraCalcInfo)) |
|
|
|
|
|
InitCameraCalcInfoRelated(cameraCalcInfo); |
|
|
|
|
|
|
|
|
|
|
|
if (World2CameraMatrix == null || MarkLabelInfoList.Count == 0) |
|
|
if (World2CameraMatrix == null || _markLabelInfoList.Count == 0) |
|
|
return; |
|
|
return resultList; |
|
|
|
|
|
|
|
|
for (int index = 0; index < MarkLabelInfoList.Count; index++) |
|
|
foreach (MarkLabelCalcInfo item in _markLabelInfoList) |
|
|
{ |
|
|
{ |
|
|
MarkLabelCalcInfo label = MarkLabelInfoList[index]; |
|
|
Matrix<double> labelC2WMatrix = ConvertCameraToWorld(item); |
|
|
Matrix<double> labelC2WMatrix = ConvertCameraToWorld(label); |
|
|
|
|
|
Matrix<double> labelPointMatrix = MBuilder.DenseOfArray(new double[,] |
|
|
Matrix<double> labelPointMatrix = MBuilder.DenseOfArray(new double[,] |
|
|
{ |
|
|
{ |
|
|
{ label.CanvasWidth / CameraCalcInfo.ImageWidth - 0.5 }, |
|
|
{ item.CanvasWidth / _cameraCalcInfo.ImageWidth - 0.5 }, |
|
|
{ label.CanvasHeight / CameraCalcInfo.ImageHeight - 0.5 }, |
|
|
{ item.CanvasHeight / _cameraCalcInfo.ImageHeight - 0.5 }, |
|
|
{ 1 } |
|
|
{ 1 } |
|
|
}); |
|
|
}); |
|
|
Matrix<double> lResult = labelC2WMatrix.Multiply(labelPointMatrix); |
|
|
Matrix<double> lResult = labelC2WMatrix.Multiply(labelPointMatrix); |
|
@ -65,18 +55,19 @@ public abstract class MarkSearcherBase |
|
|
|
|
|
|
|
|
double x = pResult[0, 0] / pResult[2, 0] + 0.5; |
|
|
double x = pResult[0, 0] / pResult[2, 0] + 0.5; |
|
|
double y = pResult[1, 0] / pResult[2, 0] + 0.5; |
|
|
double y = pResult[1, 0] / pResult[2, 0] + 0.5; |
|
|
MarkLabelCalcResult labelCalcResult = new(); |
|
|
MarkLabelCalcResult labelCalcResult; |
|
|
if (x > 0.99 || x < 0.01 || y > 0.99 || y < 0.01 || pResult[2, 0] < 0) |
|
|
if (x > 0.99 || x < 0.01 || y > 0.99 || y < 0.01 || pResult[2, 0] < 0) |
|
|
{ |
|
|
labelCalcResult = MarkLabelCalcResult.New(item.Id, false); |
|
|
labelCalcResult.InFlag = false; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
else |
|
|
{ |
|
|
labelCalcResult = MarkLabelCalcResult.New(item.Id, true, (x * _cameraCalcInfo.ImageWidth), (y * _cameraCalcInfo.ImageHeight)); |
|
|
labelCalcResult.InFlag = true; |
|
|
resultList.Add(labelCalcResult); |
|
|
labelCalcResult.CanvasLeft = x * CameraCalcInfo.ImageWidth; |
|
|
|
|
|
labelCalcResult.CanvasTop = y * CameraCalcInfo.ImageHeight; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
return resultList; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<List<MarkLabelCalcResult>> CalcAsync() |
|
|
|
|
|
{ |
|
|
|
|
|
return await Task.Run(Calc); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -84,12 +75,11 @@ public abstract class MarkSearcherBase |
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
/// <param name="newInfo"></param>
|
|
|
/// <param name="newInfo"></param>
|
|
|
/// <returns></returns>
|
|
|
/// <returns></returns>
|
|
|
protected bool IsCameraRotate(CameraCalcInfo newInfo) |
|
|
protected bool IsCameraRotate(PtzInfo newInfo) |
|
|
{ |
|
|
{ |
|
|
return CameraCalcInfo == null || |
|
|
return _cameraCalcInfo.PtzInfo.Pan != newInfo.Pan || |
|
|
CameraCalcInfo.PtzInfo.Pan != newInfo.PtzInfo.Pan || |
|
|
_cameraCalcInfo.PtzInfo.Tilt != newInfo.Tilt || |
|
|
CameraCalcInfo.PtzInfo.Tilt != newInfo.PtzInfo.Tilt || |
|
|
_cameraCalcInfo.PtzInfo.Zoom != newInfo.Zoom; |
|
|
CameraCalcInfo.PtzInfo.Zoom != newInfo.PtzInfo.Zoom; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
@ -204,4 +194,39 @@ public abstract class MarkSearcherBase |
|
|
protected abstract PointF GetFOfMatrixByZoomPos(double zoomPos); |
|
|
protected abstract PointF GetFOfMatrixByZoomPos(double zoomPos); |
|
|
|
|
|
|
|
|
#endregion Util
|
|
|
#endregion Util
|
|
|
|
|
|
|
|
|
|
|
|
#region Operate Attr
|
|
|
|
|
|
|
|
|
|
|
|
protected void UpdateCameraCalcInfoRelated(CameraCalcInfo cameraCalcInfo) |
|
|
|
|
|
{ |
|
|
|
|
|
_cameraCalcInfo = cameraCalcInfo; |
|
|
|
|
|
CalcSensor(); |
|
|
|
|
|
World2CameraMatrix = ConvertWorldToCamera(cameraCalcInfo); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void UpdateCameraCalcInfo(PtzInfo ptzInfo) |
|
|
|
|
|
{ |
|
|
|
|
|
if (IsCameraRotate(ptzInfo)) |
|
|
|
|
|
{ |
|
|
|
|
|
_cameraCalcInfo.PtzInfo = ptzInfo; |
|
|
|
|
|
World2CameraMatrix = ConvertWorldToCamera(_cameraCalcInfo); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void AddMarkLabelCalcInfo(MarkLabelCalcInfo markLabelCalcInfo) |
|
|
|
|
|
{ |
|
|
|
|
|
_markLabelInfoList.Add(markLabelCalcInfo); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public bool ExistsMarkLabelCalcInfo(object id) |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (MarkLabelCalcInfo info in _markLabelInfoList) |
|
|
|
|
|
{ |
|
|
|
|
|
if (info.Id.Equals(id)) |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endregion Operate Attr
|
|
|
} |
|
|
} |