Browse Source

feat: 完善后端标签追踪功能

master
fajiao 2 years ago
parent
commit
43466f032e
  1. 35
      Cis.Application/Cb/Service/CbCameraService.cs
  2. 36
      Cis.Application/Cis.Application.xml
  3. 16
      Cis.Application/Cm/Entity/CmMarkLabel.cs
  4. 12
      Cis.Application/Cm/Service/CmMarkGroupService.cs
  5. 39
      Cis.Application/Cm/Service/CmMarkLabelService.cs
  6. 17
      Cis.Application/Core/Algo/HikMarkSeacher.cs
  7. 73
      Cis.Application/Core/Algo/MarkSearcherBase.cs
  8. 107
      Cis.Application/Core/Center/CameraDataCenter.cs
  9. 59
      Cis.Application/Core/Entity/CameraCalcInfo.cs
  10. 28
      Cis.Application/Core/Service/MarkSearchService.cs
  11. 2
      Cis.Application/Startup.cs
  12. 12
      Cis.Application/Sys/Service/SysDictDataService.cs
  13. 12
      Cis.Application/Sys/Service/SysDictTypeService.cs
  14. 12
      Cis.Application/Tb/Service/TbPtzCameraService.cs

35
Cis.Application/Cb/Service/CbCameraService.cs

@ -15,6 +15,24 @@ public class CbCameraService : IDynamicApiController, ITransient
_cbCameraRep = cbCameraRep; _cbCameraRep = cbCameraRep;
} }
[HttpPost]
public async Task<bool> Add([FromForm] CbCamera entity)
{
return await _cbCameraRep.InsertAsync(entity);
}
[HttpPost]
public async Task<bool> Update([FromForm] CbCamera entity)
{
return await _cbCameraRep.UpdateAsync(entity);
}
[HttpPost]
public async Task<bool> Delete([FromForm] CbCamera entity)
{
return await _cbCameraRep.DeleteAsync(entity);
}
[HttpGet] [HttpGet]
public async Task<CbCamera> Get(long id) public async Task<CbCamera> Get(long id)
{ {
@ -41,21 +59,4 @@ public class CbCameraService : IDynamicApiController, ITransient
return list; return list;
} }
[HttpPost]
public async Task Add(CbCamera entity)
{
await _cbCameraRep.InsertAsync(entity);
}
[HttpPost]
public async Task Update(CbCamera entity)
{
await _cbCameraRep.UpdateAsync(entity);
}
[HttpPost]
public async Task Delete(CbCamera entity)
{
await _cbCameraRep.DeleteAsync(entity);
}
} }

36
Cis.Application/Cis.Application.xml

@ -297,14 +297,14 @@
循环运行 循环运行
</summary> </summary>
</member> </member>
<member name="M:Cis.Application.Core.CameraDataCenter.ActiveCamera(System.Int64)"> <member name="M:Cis.Application.Core.CameraDataCenter.ActivateSearcher(System.Int64)">
<summary> <summary>
激活 cbCamera 进入运算 激活 cbCamera 进入运算
</summary> </summary>
<param name="cameraId"></param> <param name="cameraId"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Cis.Application.Core.CameraDataCenter.DeActiveCamera(System.Int64)"> <member name="M:Cis.Application.Core.CameraDataCenter.DeActivateSearcher(System.Int64)">
<summary> <summary>
解除 cbCamera 进入运算 解除 cbCamera 进入运算
</summary> </summary>
@ -356,14 +356,14 @@
Ptz 信息 Ptz 信息
</summary> </summary>
</member> </member>
<member name="P:Cis.Application.Core.CameraCalcInfo.ImageWidth"> <member name="P:Cis.Application.Core.CameraCalcInfo.VideoWidth">
<summary> <summary>
图像的宽度 视频的宽度
</summary> </summary>
</member> </member>
<member name="P:Cis.Application.Core.CameraCalcInfo.ImageHeight"> <member name="P:Cis.Application.Core.CameraCalcInfo.VideoHeight">
<summary> <summary>
图像的高度 视频的高度
</summary> </summary>
</member> </member>
<member name="P:Cis.Application.Core.CameraCalcInfo.MinFocusX"> <member name="P:Cis.Application.Core.CameraCalcInfo.MinFocusX">
@ -406,24 +406,24 @@
Ptz 信息 Ptz 信息
</summary> </summary>
</member> </member>
<member name="P:Cis.Application.Core.MarkLabelCalcInfo.CanvasWidth"> <member name="P:Cis.Application.Core.MarkLabelCalcInfo.VideoWidth">
<summary> <summary>
画布宽度 视频宽度
</summary> </summary>
</member> </member>
<member name="P:Cis.Application.Core.MarkLabelCalcInfo.CanvasHeight"> <member name="P:Cis.Application.Core.MarkLabelCalcInfo.VideoHeight">
<summary> <summary>
画布高度 视频高度
</summary> </summary>
</member> </member>
<member name="P:Cis.Application.Core.MarkLabelCalcInfo.CanvasLeft"> <member name="P:Cis.Application.Core.MarkLabelCalcInfo.CanvasLeftRatio">
<summary> <summary>
画布 left 距离 画布 left 距离比例
</summary> </summary>
</member> </member>
<member name="P:Cis.Application.Core.MarkLabelCalcInfo.CanvasTop"> <member name="P:Cis.Application.Core.MarkLabelCalcInfo.CanvasTopRatio">
<summary> <summary>
画布 top 距离 画布 top 距离比例
</summary> </summary>
</member> </member>
<member name="T:Cis.Application.Core.MarkLabelCalcResult"> <member name="T:Cis.Application.Core.MarkLabelCalcResult">
@ -442,14 +442,14 @@
false 不显示(不在当前视频画面里面) false 不显示(不在当前视频画面里面)
</summary> </summary>
</member> </member>
<member name="P:Cis.Application.Core.MarkLabelCalcResult.CanvasLeft"> <member name="P:Cis.Application.Core.MarkLabelCalcResult.CanvasLeftRatio">
<summary> <summary>
画布 left 距离 画布 left 距离比例
</summary> </summary>
</member> </member>
<member name="P:Cis.Application.Core.MarkLabelCalcResult.CanvasTop"> <member name="P:Cis.Application.Core.MarkLabelCalcResult.CanvasTopRatio">
<summary> <summary>
画布 top 距离 画布 top 距离比例
</summary> </summary>
</member> </member>
<member name="M:Cis.Application.Startup.ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)"> <member name="M:Cis.Application.Startup.ConfigureServices(Microsoft.Extensions.DependencyInjection.IServiceCollection)">

16
Cis.Application/Cm/Entity/CmMarkLabel.cs

@ -43,17 +43,17 @@ public class CmMarkLabel : EntityBase
[SugarColumn(ColumnDescription = "Zoom坐标")] [SugarColumn(ColumnDescription = "Zoom坐标")]
public double ZoomPosition { get; set; } public double ZoomPosition { get; set; }
[SugarColumn(ColumnDescription = "画布宽度")] [SugarColumn(ColumnDescription = "视频宽度")]
public double CanvasWidth { get; set; } public double VideoWidth { get; set; }
[SugarColumn(ColumnDescription = "画布高度")] [SugarColumn(ColumnDescription = "视频高度")]
public double CanvasHeight { get; set; } public double VideoHeight { get; set; }
[SugarColumn(ColumnDescription = "画布 left 距离")] [SugarColumn(ColumnDescription = "画布 left 距离比例")]
public double CanvasLeft { get; set; } public double CanvasLeftRatio { get; set; }
[SugarColumn(ColumnDescription = "画布 top 距离")] [SugarColumn(ColumnDescription = "画布 top 距离比例")]
public double CanvasTop { get; set; } public double CanvasTopRatio { get; set; }
/// <summary> /// <summary>
/// 备注 /// 备注

12
Cis.Application/Cm/Service/CmMarkGroupService.cs

@ -16,21 +16,21 @@ public class CmMarkGroupService : IDynamicApiController, ITransient
} }
[HttpPost] [HttpPost]
public async Task Add(CmMarkGroup entity) public async Task<bool> Add([FromForm] CmMarkGroup entity)
{ {
await _cmMarkGroupRep.InsertAsync(entity); return await _cmMarkGroupRep.InsertAsync(entity);
} }
[HttpPost] [HttpPost]
public async Task Update(CmMarkGroup entity) public async Task<bool> Update([FromForm] CmMarkGroup entity)
{ {
await _cmMarkGroupRep.UpdateAsync(entity); return await _cmMarkGroupRep.UpdateAsync(entity);
} }
[HttpPost] [HttpPost]
public async Task Delete(CmMarkGroup entity) public async Task<bool> Delete([FromForm] CmMarkGroup entity)
{ {
await _cmMarkGroupRep.DeleteAsync(entity); return await _cmMarkGroupRep.DeleteAsync(entity);
} }
[HttpGet] [HttpGet]

39
Cis.Application/Cm/Service/CmMarkLabelService.cs

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq; using Cis.Application.Core;
using Newtonsoft.Json.Linq;
namespace Cis.Application.Cm; namespace Cis.Application.Cm;
@ -10,27 +11,50 @@ public class CmMarkLabelService : IDynamicApiController, ITransient
{ {
private readonly SqlSugarRepository<CmMarkLabel> _cmMarkLabelRep; private readonly SqlSugarRepository<CmMarkLabel> _cmMarkLabelRep;
public CmMarkLabelService(SqlSugarRepository<CmMarkLabel> cmMarkLabelRep) private CameraDataCenter _cameraDataCenter { get; set; }
public CmMarkLabelService(CameraDataCenter cameraDataCenter,
SqlSugarRepository<CmMarkLabel> cmMarkLabelRep)
{ {
_cameraDataCenter = cameraDataCenter;
_cmMarkLabelRep = cmMarkLabelRep; _cmMarkLabelRep = cmMarkLabelRep;
} }
[HttpPost] [HttpPost]
public async Task Add(CmMarkLabel entity) public async Task<bool> Add([FromForm] CmMarkLabel entity)
{
PtzInfo ptzInfo = _cameraDataCenter.GetCameraPtzInfo(entity.CbCameraId);
if (ptzInfo == null)
return false;
entity.PanPosition = ptzInfo.Pan;
entity.TiltPosition = ptzInfo.Tilt;
entity.ZoomPosition = ptzInfo.Zoom;
return await _cmMarkLabelRep.InsertAsync(entity);
}
[HttpPost]
public async Task<long> AddReturnId([FromForm] CmMarkLabel entity)
{ {
PtzInfo ptzInfo = _cameraDataCenter.GetCameraPtzInfo(entity.CbCameraId);
if (ptzInfo == null)
return 0;
entity.PanPosition = ptzInfo.Pan;
entity.TiltPosition = ptzInfo.Tilt;
entity.ZoomPosition = ptzInfo.Zoom;
await _cmMarkLabelRep.InsertAsync(entity); await _cmMarkLabelRep.InsertAsync(entity);
return entity.Id;
} }
[HttpPost] [HttpPost]
public async Task Update(CmMarkLabel entity) public async Task<bool> Update([FromForm] CmMarkLabel entity)
{ {
await _cmMarkLabelRep.UpdateAsync(entity); return await _cmMarkLabelRep.UpdateAsync(entity);
} }
[HttpPost] [HttpPost]
public async Task Delete(CmMarkLabel entity) public async Task<bool> Delete([FromForm] CmMarkLabel entity)
{ {
await _cmMarkLabelRep.DeleteAsync(entity); return await _cmMarkLabelRep.DeleteAsync(entity);
} }
[HttpGet] [HttpGet]
@ -58,5 +82,4 @@ public class CmMarkLabelService : IDynamicApiController, ITransient
.ToPageListAsync(pageObj.Index, pageObj.Size); .ToPageListAsync(pageObj.Index, pageObj.Size);
return list; return list;
} }
} }

17
Cis.Application/Core/Algo/HikMarkSeacher.cs

@ -12,7 +12,7 @@ public class HikMarkSeacher : MarkSearcherBase
protected override double ConvertPanPosToAngle(double panPos) protected override double ConvertPanPosToAngle(double panPos)
{ {
double ret = (0.1 * HexToDecMa(panPos)) / (180 * Math.PI); double ret = 0.1 * HexToDecMa(panPos) / 180 * Math.PI;
ret = (ret >= 0) ? ret : (2 * Math.PI + ret); ret = (ret >= 0) ? ret : (2 * Math.PI + ret);
return ret; return ret;
} }
@ -24,7 +24,7 @@ public class HikMarkSeacher : MarkSearcherBase
ndiff = HexToDecMa(tiltPos) - HexToDecMa(tiltMinPos); ndiff = HexToDecMa(tiltPos) - HexToDecMa(tiltMinPos);
else else
ndiff = HexToDecMa(tiltPos) + HexToDecMa(13824) - HexToDecMa(tiltMinPos); ndiff = HexToDecMa(tiltPos) + HexToDecMa(13824) - HexToDecMa(tiltMinPos);
double ret = (0.1 * ndiff) / (180 * Math.PI); double ret = 0.1 * ndiff / 180 * Math.PI;
return ret; return ret;
} }
@ -40,8 +40,8 @@ public class HikMarkSeacher : MarkSearcherBase
protected override void CalcSensor() protected override void CalcSensor()
{ {
_cameraCalcInfo.MinFocusX = 1783.6 / _cameraCalcInfo.ImageWidth; _cameraCalcInfo.MinFocusX = 1783.6 / _cameraCalcInfo.VideoWidth;
_cameraCalcInfo.MinFocusY = 1781.4 / _cameraCalcInfo.ImageHeight; _cameraCalcInfo.MinFocusY = 1781.4 / _cameraCalcInfo.VideoHeight;
} }
#endregion Implement #endregion Implement
@ -67,11 +67,14 @@ public class HikMarkSeacher : MarkSearcherBase
return ret; return ret;
} }
protected double HexToDecMa(double wHex) protected int HexToDecMa(double wHex)
{ {
double ret = (wHex / 4096) * 1000 + ((wHex % 4096) / 256) * 100 + ((wHex % 256) / 16) * 10 + (wHex % 16); int wHexInt = wHex.ToInt();
int ret = (wHexInt / 4096) * 1000 + ((wHexInt % 4096) / 256) * 100 + ((wHexInt % 256) / 16) * 10 + (wHexInt % 16);
return ret; return ret;
} }
#endregion Util #endregion Util
} }

73
Cis.Application/Core/Algo/MarkSearcherBase.cs

@ -1,4 +1,5 @@
using MathNet.Numerics.LinearAlgebra; using MathNet.Numerics.LinearAlgebra;
using MathNet.Numerics.LinearAlgebra.Double;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Drawing; using System.Drawing;
@ -23,7 +24,7 @@ public abstract class MarkSearcherBase
/// </summary> /// </summary>
protected ConcurrentDictionary<long, MarkLabelCalcInfo> _markLabelInfoDict { get; set; } = new(); protected ConcurrentDictionary<long, MarkLabelCalcInfo> _markLabelInfoDict { get; set; } = new();
protected MatrixBuilder<double> MBuilder { get; set; } = Matrix<double>.Build; //protected MatrixBuilder<double> MBuilder { get; set; } = Matrix<double>.Build;
/// <summary> /// <summary>
/// 世界坐标转化为相机坐标矩阵 /// 世界坐标转化为相机坐标矩阵
@ -53,11 +54,11 @@ public abstract class MarkSearcherBase
foreach (MarkLabelCalcInfo item in _markLabelInfoDict.Values) foreach (MarkLabelCalcInfo item in _markLabelInfoDict.Values)
{ {
Matrix<double> labelC2WMatrix = ConvertCameraToWorld(item); Matrix<double> labelC2WMatrix = ConvertCameraToWorld(item);
Matrix<double> labelPointMatrix = MBuilder.DenseOfArray(new double[,] Matrix<double> labelPointMatrix = new DenseMatrix(3, 1, new double[]
{ {
{ item.CanvasWidth / _cameraCalcInfo.ImageWidth - 0.5 }, (item.CanvasLeftRatio * item.VideoWidth) / _cameraCalcInfo.VideoWidth - 0.5 ,
{ item.CanvasHeight / _cameraCalcInfo.ImageHeight - 0.5 }, (item.CanvasTopRatio * item.VideoHeight) / _cameraCalcInfo.VideoHeight - 0.5 ,
{ 1 } 1
}); });
Matrix<double> lResult = labelC2WMatrix.Multiply(labelPointMatrix); Matrix<double> lResult = labelC2WMatrix.Multiply(labelPointMatrix);
Matrix<double> pResult = World2CameraMatrix.Multiply(lResult); Matrix<double> pResult = World2CameraMatrix.Multiply(lResult);
@ -68,7 +69,7 @@ public abstract class MarkSearcherBase
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 = MarkLabelCalcResult.New(item.Id, false);
else else
labelCalcResult = MarkLabelCalcResult.New(item.Id, true, (x * _cameraCalcInfo.ImageWidth), (y * _cameraCalcInfo.ImageHeight)); labelCalcResult = MarkLabelCalcResult.New(item.Id, true, x, y);
resultList.Add(labelCalcResult); resultList.Add(labelCalcResult);
} }
return resultList; return resultList;
@ -86,9 +87,10 @@ public abstract class MarkSearcherBase
/// <returns></returns> /// <returns></returns>
protected bool IsCameraRotate(PtzInfo newInfo) protected bool IsCameraRotate(PtzInfo newInfo)
{ {
return _cameraCalcInfo.PtzInfo.Pan != newInfo.Pan || bool ret = _cameraCalcInfo.PtzInfo.Pan != newInfo.Pan ||
_cameraCalcInfo.PtzInfo.Tilt != newInfo.Tilt || _cameraCalcInfo.PtzInfo.Tilt != newInfo.Tilt ||
_cameraCalcInfo.PtzInfo.Zoom != newInfo.Zoom; _cameraCalcInfo.PtzInfo.Zoom != newInfo.Zoom;
return ret;
} }
/// <summary> /// <summary>
@ -106,30 +108,31 @@ public abstract class MarkSearcherBase
double sinTilt = Math.Sin(tiltAngle); double sinTilt = Math.Sin(tiltAngle);
double cosTilt = Math.Cos(tiltAngle); double cosTilt = Math.Cos(tiltAngle);
Matrix<double> fMatrix = MBuilder.DenseOfArray(new double[,] Matrix<double> fMatrix = new DenseMatrix(3, 3, new double[]
{ {
{ pointF.X, 0, 0 }, pointF.X, 0, 0 ,
{ 0, pointF.Y, 0 }, 0, pointF.Y, 0 ,
{ 0, 0, 1 }, 0, 0, 1 ,
}); });
Matrix<double> rotateTiltMatrix = MBuilder.DenseOfArray(new double[,] Matrix<double> rotateTiltMatrix = new DenseMatrix(3, 3, new double[]
{ {
{ 1, 0, 0 }, 1, 0, 0 ,
{ 0, cosTilt, sinTilt }, 0, cosTilt, sinTilt ,
{ 0, -sinTilt, cosTilt }, 0, -sinTilt, cosTilt ,
}); });
Matrix<double> midResult = fMatrix.Multiply(rotateTiltMatrix); Matrix<double> midResult = fMatrix.Multiply(rotateTiltMatrix);
Matrix<double> rotatePanMatrix = MBuilder.DenseOfArray(new double[,] Matrix<double> rotatePanMatrix = new DenseMatrix(3, 3, new double[]
{ {
{ cosPan, 0, sinPan }, cosPan, 0, sinPan ,
{ 0, 1, 0 }, 0, 1, 0 ,
{ -sinPan, 0, cosPan }, -sinPan, 0, cosPan ,
}); });
return midResult.Multiply(rotatePanMatrix); var last = midResult.Multiply(rotatePanMatrix);
return last;
} }
/// <summary> /// <summary>
@ -147,27 +150,31 @@ public abstract class MarkSearcherBase
double sinTilt = Math.Sin(tiltAngle); double sinTilt = Math.Sin(tiltAngle);
double cosTilt = Math.Cos(tiltAngle); double cosTilt = Math.Cos(tiltAngle);
Matrix<double> rotatePanMatrix = MBuilder.DenseOfArray(new double[,] { Matrix<double> rotatePanMatrix = new DenseMatrix(3, 3, new double[]
{ cosPan, 0, -sinPan }, {
{ 0, 1, 0 }, cosPan, 0, -sinPan ,
{ sinPan, 0, cosPan } 0, 1, 0 ,
sinPan, 0, cosPan
}); });
Matrix<double> rotateTiltMatrix = MBuilder.DenseOfArray(new double[,] { Matrix<double> rotateTiltMatrix = new DenseMatrix(3, 3, new double[]
{ 1, 0, 0 }, {
{ 0, cosTilt, -sinTilt }, 1, 0, 0 ,
{ 0, sinTilt, cosTilt } 0, cosTilt, -sinTilt ,
0, sinTilt, cosTilt
}); });
Matrix<double> midResult = rotatePanMatrix.Multiply(rotateTiltMatrix); Matrix<double> midResult = rotatePanMatrix.Multiply(rotateTiltMatrix);
Matrix<double> fMatrix = MBuilder.DenseOfArray(new double[,] { Matrix<double> fMatrix = new DenseMatrix(3, 3, new double[]
{ (1 / pointF.X), 0, 0 }, {
{ 0, (1 / pointF.Y), 0 }, (1 / pointF.X), 0, 0 ,
{ 0, 0, 1 } 0, (1 / pointF.Y), 0 ,
0, 0, 1
}); });
return midResult.Multiply(fMatrix); var last = midResult.Multiply(fMatrix);
return last;
} }
/// <summary> /// <summary>

107
Cis.Application/Core/Center/CameraDataCenter.cs

@ -110,10 +110,10 @@ public class CameraDataCenter
{ {
long cameraId = pair.Key; long cameraId = pair.Key;
MarkSearcherBase markSearcher = pair.Value; MarkSearcherBase markSearcher = pair.Value;
string cameraIp = _cbCameraId2IpDict[cameraId]; bool ret = _cbCameraId2IpDict.TryGetValue(cameraId, out string cameraIp);
if (cameraIp == null) continue; if (!ret) continue;
PtzInfo ptzInfo = _cameraPtzInfoDict[cameraIp]; ret = _cameraPtzInfoDict.TryGetValue(cameraIp, out PtzInfo ptzInfo);
if (ptzInfo == null) continue; if (!ret) continue;
markSearcher.UpdateCameraCalcInfo(ptzInfo); markSearcher.UpdateCameraCalcInfo(ptzInfo);
List<MarkLabelCalcResult> resultList = markSearcher.Calc(); List<MarkLabelCalcResult> resultList = markSearcher.Calc();
_markLabelCalcResultListDict[cameraId] = resultList; _markLabelCalcResultListDict[cameraId] = resultList;
@ -129,29 +129,25 @@ public class CameraDataCenter
/// </summary> /// </summary>
/// <param name="cameraId"></param> /// <param name="cameraId"></param>
/// <returns></returns> /// <returns></returns>
public bool ActiveCamera(long cameraId) public bool ActivateSearcher(long cameraId)
{ {
try try
{ {
msDictLock.EnterWriteLock(); msDictLock.EnterWriteLock();
if (_markSearcherDict.ExistsKey(cameraId)) if (_markSearcherDict.ContainsKey(cameraId))
return false; return false;
// 获取 cbCamera // 获取 cbCamera
CbCamera cbCamera = _cbCameraRep.GetById(cameraId); CbCamera cbCamera = _cbCameraRep.GetById(cameraId);
if (cbCamera == null) return false; if (cbCamera == null) return false;
// 获取 tbPtzCamera // 获取 tbPtzCamera
TbPtzCamera tbPtzCamera;
string cameraIp = cbCamera.Ip; string cameraIp = cbCamera.Ip;
if (!_tbPtzCameraDict.ExistsKey(cameraIp)) bool ret = _tbPtzCameraDict.TryGetValue(cameraIp, out TbPtzCamera tbPtzCamera);
if (!ret)
{ {
tbPtzCamera = _tbPtzCameraRep.GetFirst(u => u.Ip == cameraIp); tbPtzCamera = _tbPtzCameraRep.GetFirst(u => u.Ip == cameraIp);
if (tbPtzCamera == null) return false; if (tbPtzCamera == null) return false;
_tbPtzCameraDict[cameraIp] = tbPtzCamera; _tbPtzCameraDict[cameraIp] = tbPtzCamera;
} }
else
{
tbPtzCamera = _tbPtzCameraDict[cameraIp];
}
// 存储 cbCamera id 对应 ip 关系 // 存储 cbCamera id 对应 ip 关系
_cbCameraId2IpDict[cbCamera.Id] = cameraIp; _cbCameraId2IpDict[cbCamera.Id] = cameraIp;
// 创建 cameraCalcInfo // 创建 cameraCalcInfo
@ -166,10 +162,10 @@ public class CameraDataCenter
MarkLabelCalcInfo markLabelCalcInfo = MarkLabelCalcInfo.New( MarkLabelCalcInfo markLabelCalcInfo = MarkLabelCalcInfo.New(
item.Id, item.Id,
PtzInfo.New(item.PanPosition, item.TiltPosition, item.ZoomPosition), PtzInfo.New(item.PanPosition, item.TiltPosition, item.ZoomPosition),
item.CanvasWidth, item.VideoWidth,
item.CanvasHeight, item.VideoHeight,
item.CanvasLeft, item.CanvasLeftRatio,
item.CanvasTop item.CanvasTopRatio
); );
markSeacher.AddMarkLabelCalcInfo(markLabelCalcInfo); markSeacher.AddMarkLabelCalcInfo(markLabelCalcInfo);
} }
@ -188,7 +184,7 @@ public class CameraDataCenter
/// </summary> /// </summary>
/// <param name="cameraId"></param> /// <param name="cameraId"></param>
/// <returns></returns> /// <returns></returns>
public bool DeActiveCamera(long cameraId) public bool DeActivateSearcher(long cameraId)
{ {
try try
{ {
@ -203,11 +199,16 @@ public class CameraDataCenter
return true; return true;
} }
public bool AddCameraMarkLabel(long cameraId, long markLabelId) public bool IsExistSearcher(long cameraId)
{
return _markSearcherDict.ContainsKey(cameraId);
}
public bool ActivateMarkLabel(long cameraId, long markLabelId)
{ {
if (!_markSearcherDict.ExistsKey(cameraId)) bool ret = _markSearcherDict.TryGetValue(cameraId, out MarkSearcherBase markSearcher);
if (!ret)
return false; return false;
MarkSearcherBase markSearcher = _markSearcherDict[cameraId];
if (markSearcher.ExistsMarkLabelCalcInfo(markLabelId)) if (markSearcher.ExistsMarkLabelCalcInfo(markLabelId))
return false; return false;
CmMarkLabel label = _cmMarkLableRep.GetById(markLabelId); CmMarkLabel label = _cmMarkLableRep.GetById(markLabelId);
@ -216,56 +217,86 @@ public class CameraDataCenter
MarkLabelCalcInfo markLabelCalcInfo = MarkLabelCalcInfo.New( MarkLabelCalcInfo markLabelCalcInfo = MarkLabelCalcInfo.New(
label.Id, label.Id,
PtzInfo.New(label.PanPosition, label.TiltPosition, label.ZoomPosition), PtzInfo.New(label.PanPosition, label.TiltPosition, label.ZoomPosition),
label.CanvasWidth, label.VideoWidth,
label.CanvasHeight, label.VideoHeight,
label.CanvasLeft, label.CanvasLeftRatio,
label.CanvasTop label.CanvasTopRatio
); );
return markSearcher.AddMarkLabelCalcInfo(markLabelCalcInfo); return markSearcher.AddMarkLabelCalcInfo(markLabelCalcInfo);
} }
public bool DeleteCameraMarkLabel(long cameraId, long markLabelId) public bool DectivateMarkLabel(long cameraId, long markLabelId)
{ {
if (!_markSearcherDict.ExistsKey(cameraId)) bool ret = _markSearcherDict.TryGetValue(cameraId, out MarkSearcherBase markSearcher);
return false; return ret ? markSearcher.DeleteMarkLabelCalcInfo(markLabelId) : false;
MarkSearcherBase markSearcher = _markSearcherDict[cameraId]; }
return markSearcher.DeleteMarkLabelCalcInfo(markLabelId);
public bool IsExistCameraMarkLabel(long cameraId, long markLabelId)
{
bool ret = _markSearcherDict.TryGetValue(cameraId, out MarkSearcherBase markSearcher) &&
markSearcher.ExistsMarkLabelCalcInfo(markLabelId);
return ret;
} }
public List<MarkLabelCalcResult> GetMarkLabelCalcResultList(long cameraId) public List<MarkLabelCalcResult> GetMarkLabelCalcResultList(long cameraId)
{ {
return null; bool ret = _markLabelCalcResultListDict.TryGetValue(cameraId, out List<MarkLabelCalcResult> list);
return ret ? list : new();
}
public PtzInfo GetCameraPtzInfo(long cameraId)
{
PtzInfo ptzInfo = null;
bool ret = _cbCameraId2IpDict.TryGetValue(cameraId,out string cameraIp) &&
_cameraPtzInfoDict.TryGetValue(cameraIp, out ptzInfo);
return ret ? ptzInfo : null;
}
public async Task<bool> ActivateSearcherAsync(long cameraId)
{
return await Task.Run(() =>
{
return ActivateSearcher(cameraId);
});
}
public async Task<bool> DeActivateSearcherAsync(long cameraId)
{
return await Task.Run(() =>
{
return DeActivateSearcher(cameraId);
});
} }
public async Task<bool> ActiveCameraAsync(long cameraId) public async Task<bool> IsExistSearcherAsync(long cameraId)
{ {
return await Task.Run(() => return await Task.Run(() =>
{ {
return ActiveCamera(cameraId); return IsExistSearcher(cameraId);
}); });
} }
public async Task<bool> DeActiveCameraAsync(long cameraId) public async Task<bool> ActivateMarkLabelAsync(long cameraId, long markLabelId)
{ {
return await Task.Run(() => return await Task.Run(() =>
{ {
return DeActiveCamera(cameraId); return ActivateMarkLabel(cameraId, markLabelId);
}); });
} }
public async Task<bool> AddCameraMarkLabelAsync(long cameraId, long markLabelId) public async Task<bool> DeactivateMarkLabelAsync(long cameraId, long markLabelId)
{ {
return await Task.Run(() => return await Task.Run(() =>
{ {
return AddCameraMarkLabel(cameraId, markLabelId); return DectivateMarkLabel(cameraId, markLabelId);
}); });
} }
public async Task<bool> DeleteCameraMarkLabelAsync(long cameraId, long markLabelId) public async Task<bool> IsExistMarkLabelAysnc(long cameraId, long markLabelId)
{ {
return await Task.Run(() => return await Task.Run(() =>
{ {
return DeleteCameraMarkLabel(cameraId, markLabelId); return IsExistCameraMarkLabel(cameraId, markLabelId);
}); });
} }

59
Cis.Application/Core/Entity/CameraCalcInfo.cs

@ -16,14 +16,14 @@ public class CameraCalcInfo
public PtzInfo PtzInfo { get; set; } public PtzInfo PtzInfo { get; set; }
/// <summary> /// <summary>
/// 图像的宽度 /// 视频的宽度
/// </summary> /// </summary>
public int ImageWidth { get; set; } = 1920; public int VideoWidth { get; set; } = 1920;
/// <summary> /// <summary>
/// 图像的高度 /// 视频的高度
/// </summary> /// </summary>
public int ImageHeight { get; set; } = 1080; public int VideoHeight { get; set; } = 1080;
/// <summary> /// <summary>
/// 最小焦距 /// 最小焦距
@ -40,6 +40,17 @@ public class CameraCalcInfo
PtzInfo = ptzInfo PtzInfo = ptzInfo
}; };
} }
public static CameraCalcInfo New(long id, PtzInfo ptzInfo, int videoWidth, int videoHeight)
{
return new()
{
Id = id,
PtzInfo = ptzInfo,
VideoWidth = videoWidth,
VideoHeight = videoHeight
};
}
} }
/// <summary> /// <summary>
@ -89,35 +100,35 @@ public class MarkLabelCalcInfo
public PtzInfo PtzInfo { get; set; } public PtzInfo PtzInfo { get; set; }
/// <summary> /// <summary>
/// 画布宽度 /// 视频宽度
/// </summary> /// </summary>
public double CanvasWidth { get; set; } public double VideoWidth { get; set; }
/// <summary> /// <summary>
/// 画布高度 /// 视频高度
/// </summary> /// </summary>
public double CanvasHeight { get; set; } public double VideoHeight { get; set; }
/// <summary> /// <summary>
/// 画布 left 距离 /// 画布 left 距离比例
/// </summary> /// </summary>
public double CanvasLeft { get; set; } public double CanvasLeftRatio { get; set; }
/// <summary> /// <summary>
/// 画布 top 距离 /// 画布 top 距离比例
/// </summary> /// </summary>
public double CanvasTop { get; set; } public double CanvasTopRatio { get; set; }
public static MarkLabelCalcInfo New(long id, PtzInfo ptzInfo, double canvasWidth, double canvasHeight, double canvasLeft, double canvasTop) public static MarkLabelCalcInfo New(long id, PtzInfo ptzInfo, double videoWidth, double videoHeight, double canvasLeftRatio, double canvasTopRatio)
{ {
return new() return new()
{ {
Id = id, Id = id,
PtzInfo = ptzInfo, PtzInfo = ptzInfo,
CanvasWidth = canvasWidth, VideoWidth = videoWidth,
CanvasHeight = canvasHeight, VideoHeight = videoHeight,
CanvasLeft = canvasLeft, CanvasLeftRatio = canvasLeftRatio,
CanvasTop = canvasTop CanvasTopRatio = canvasTopRatio
}; };
} }
} }
@ -139,14 +150,14 @@ public class MarkLabelCalcResult
public bool InFlag { get; set; } public bool InFlag { get; set; }
/// <summary> /// <summary>
/// 画布 left 距离 /// 画布 left 距离比例
/// </summary> /// </summary>
public double CanvasLeft { get; set; } public double CanvasLeftRatio { get; set; }
/// <summary> /// <summary>
/// 画布 top 距离 /// 画布 top 距离比例
/// </summary> /// </summary>
public double CanvasTop { get; set; } public double CanvasTopRatio { get; set; }
public static MarkLabelCalcResult New(long id, bool inFlag) public static MarkLabelCalcResult New(long id, bool inFlag)
{ {
@ -157,14 +168,14 @@ public class MarkLabelCalcResult
}; };
} }
public static MarkLabelCalcResult New(long id, bool inFlag, double canvasLeft, double canvasTop) public static MarkLabelCalcResult New(long id, bool inFlag, double canvasLeftRatio, double canvasTopRatio)
{ {
return new() return new()
{ {
Id = id, Id = id,
InFlag = inFlag, InFlag = inFlag,
CanvasLeft = canvasLeft, CanvasLeftRatio = canvasLeftRatio,
CanvasTop = canvasTop CanvasTopRatio = canvasTopRatio
}; };
} }
} }

28
Cis.Application/Core/Service/MarkSearchService.cs

@ -17,27 +17,39 @@ public class MarkSearchService : IDynamicApiController, ITransient
} }
[HttpPost] [HttpPost]
public async Task<bool> ActivateCamera(long cameraId) public async Task<bool> ActivateSearcher([FromForm] long cameraId)
{ {
return await _cameraDataCenter.ActiveCameraAsync(cameraId); return await _cameraDataCenter.ActivateSearcherAsync(cameraId);
} }
[HttpPost] [HttpPost]
public async Task<bool> DeActiveCamera(long cameraId) public async Task<bool> DeActivateSearcher([FromForm] long cameraId)
{ {
return await _cameraDataCenter.DeActiveCameraAsync(cameraId); return await _cameraDataCenter.DeActivateSearcherAsync(cameraId);
}
[HttpGet]
public async Task<bool> IsExistSearcher(long cameraId)
{
return await _cameraDataCenter.IsExistSearcherAsync(cameraId);
} }
[HttpPost] [HttpPost]
public async Task<bool> AddCameraMarkLabel(long cameraId, long markLabelId) public async Task<bool> ActivateMarkLabel([FromForm] long cameraId, [FromForm] long markLabelId)
{ {
return await _cameraDataCenter.AddCameraMarkLabelAsync(cameraId, markLabelId); return await _cameraDataCenter.ActivateMarkLabelAsync(cameraId, markLabelId);
} }
[HttpPost] [HttpPost]
public async Task<bool> DeleteCameraMarkLabel(long cameraId, long markLabelId) public async Task<bool> DeactivateMarkLabel([FromForm] long cameraId, [FromForm] long markLabelId)
{
return await _cameraDataCenter.DeactivateMarkLabelAsync(cameraId, markLabelId);
}
[HttpGet]
public async Task<bool> IsExistMarkLabel(long cameraId,long markLabelId)
{ {
return await _cameraDataCenter.DeleteCameraMarkLabelAsync(cameraId, markLabelId); return await _cameraDataCenter.IsExistMarkLabelAysnc(cameraId, markLabelId);
} }
[HttpGet] [HttpGet]

2
Cis.Application/Startup.cs

@ -14,7 +14,7 @@ public class Startup : AppStartup
/// <param name="services"></param> /// <param name="services"></param>
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddConfigurableOptions<CameraDataOptions>(); services.AddConfigurableOptions<CameraDataOptions>();
services.AddConfigurableOptions<PtzServerOptions>(); services.AddConfigurableOptions<PtzServerOptions>();
services.AddSingleton<CameraDataCenter>(new CameraDataCenter()); services.AddSingleton<CameraDataCenter>(new CameraDataCenter());

12
Cis.Application/Sys/Service/SysDictDataService.cs

@ -16,21 +16,21 @@ public class SysDictDataService : IDynamicApiController, ITransient
} }
[HttpPost] [HttpPost]
public async Task Add(SysDictData entity) public async Task<bool> Add([FromForm] SysDictData entity)
{ {
await _sysDictDataRep.InsertAsync(entity); return await _sysDictDataRep.InsertAsync(entity);
} }
[HttpPost] [HttpPost]
public async Task Update(SysDictData entity) public async Task<bool> Update([FromForm] SysDictData entity)
{ {
await _sysDictDataRep.UpdateAsync(entity); return await _sysDictDataRep.UpdateAsync(entity);
} }
[HttpPost] [HttpPost]
public async Task Delete(SysDictData entity) public async Task<bool> Delete([FromForm] SysDictData entity)
{ {
await _sysDictDataRep.DeleteAsync(entity); return await _sysDictDataRep.DeleteAsync(entity);
} }
[HttpGet] [HttpGet]

12
Cis.Application/Sys/Service/SysDictTypeService.cs

@ -17,21 +17,21 @@ public class SysDictTypeService : IDynamicApiController, ITransient
} }
[HttpPost] [HttpPost]
public async Task Add(SysDictType entity) public async Task<bool> Add([FromForm] SysDictType entity)
{ {
await _sysDictTypeRep.InsertAsync(entity); return await _sysDictTypeRep.InsertAsync(entity);
} }
[HttpPost] [HttpPost]
public async Task Update(SysDictType entity) public async Task<bool> Update([FromForm] SysDictType entity)
{ {
await _sysDictTypeRep.UpdateAsync(entity); return await _sysDictTypeRep.UpdateAsync(entity);
} }
[HttpPost] [HttpPost]
public async Task Delete(SysDictType entity) public async Task<bool> Delete([FromForm] SysDictType entity)
{ {
await _sysDictTypeRep.DeleteAsync(entity); return await _sysDictTypeRep.DeleteAsync(entity);
} }
[HttpGet] [HttpGet]

12
Cis.Application/Tb/Service/TbPtzCameraService.cs

@ -12,21 +12,21 @@ public class TbPtzCameraService : ITransient
} }
[HttpPost] [HttpPost]
public async Task Add(TbPtzCamera entity) public async Task<bool> Add([FromForm] TbPtzCamera entity)
{ {
await _tbPtzCameraRep.InsertAsync(entity); return await _tbPtzCameraRep.InsertAsync(entity);
} }
[HttpPost] [HttpPost]
public async Task Update(TbPtzCamera entity) public async Task<bool> Update([FromForm] TbPtzCamera entity)
{ {
await _tbPtzCameraRep.UpdateAsync(entity); return await _tbPtzCameraRep.UpdateAsync(entity);
} }
[HttpPost] [HttpPost]
public async Task Delete(TbPtzCamera entity) public async Task<bool> Delete([FromForm] TbPtzCamera entity)
{ {
await _tbPtzCameraRep.DeleteAsync(entity); return await _tbPtzCameraRep.DeleteAsync(entity);
} }
[HttpGet] [HttpGet]

Loading…
Cancel
Save