|
|
@@ -7,6 +7,7 @@ using MvvmScaffoldFrame48.Model.StorageModel.Configs;
|
|
|
using MvvmScaffoldFrame48.Model.StorageModel.HikVisionCamera;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
@@ -35,7 +36,7 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
/// 设备事件委托
|
|
|
/// </summary>
|
|
|
public event EventHandler<FrameGrabbedEventArgs> FrameGrabbedEvent;
|
|
|
-
|
|
|
+ private DateTime _lastFrame = DateTime.MinValue;
|
|
|
#endregion
|
|
|
|
|
|
#region 变量
|
|
|
@@ -43,10 +44,48 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
/// 最后一次帧号记录
|
|
|
/// </summary>
|
|
|
private long lastframeNum = -1;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 帧率限制下最小帧间隔(单位ms)
|
|
|
+ /// </summary>
|
|
|
+ private double minIntervalMs;
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 是否进行取图帧率限制
|
|
|
+ /// </summary>
|
|
|
+ private bool isFrameRateLimit = false;
|
|
|
+ public bool IsFrameRateLimit
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return isFrameRateLimit;
|
|
|
+ }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ isFrameRateLimit = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 取图帧率限制
|
|
|
+ /// </summary>
|
|
|
+ private int frameRateLimit;
|
|
|
+ public int FrameRateLimit
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return frameRateLimit;
|
|
|
+ }
|
|
|
+ set
|
|
|
+ {
|
|
|
+ frameRateLimit = value;
|
|
|
+ minIntervalMs = 1000.0 / frameRateLimit;
|
|
|
+ }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region 构造函数
|
|
|
-
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// 相机构造函数 不加载相机
|
|
|
/// </summary>
|
|
|
@@ -183,7 +222,12 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
return Blresult;
|
|
|
}
|
|
|
|
|
|
- public int LoadCameraConfig(LinescanCameraParameterModel cameraParameter)
|
|
|
+ /// <summary>
|
|
|
+ /// 加载线阵相机参数
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="cameraParameter"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public int LoadLineCameraConfig(LinescanCameraParameterModel cameraParameter)
|
|
|
{
|
|
|
int result = 0;
|
|
|
_device.Parameters.SetFloatValue("ExposureTime", cameraParameter.ExposureTimeValue);
|
|
|
@@ -194,7 +238,12 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
- public int LoadCameraConfig(string cameraParameter)
|
|
|
+ /// <summary>
|
|
|
+ /// 加载线阵相机参数(从序列化字符串读取)
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="cameraParameter"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public int LoadLineCameraConfig(string cameraParameter)
|
|
|
{
|
|
|
int result = 0;
|
|
|
LinescanCameraParameterModel cameraParameterModel = XMLReadWrite.DeserializeFromString<LinescanCameraParameterModel>(cameraParameter);
|
|
|
@@ -298,24 +347,37 @@ namespace MvvmScaffoldFrame48.DLL.CameraTools
|
|
|
/// </summary>
|
|
|
private void FrameGrabbedEventHandler(object sender,FrameGrabbedEventArgs e)
|
|
|
{
|
|
|
- // 触发外部注册的事件
|
|
|
- FrameGrabbedEvent?.Invoke(this, e);
|
|
|
- if (lastframeNum == -1)
|
|
|
- {
|
|
|
- lastframeNum = e.FrameOut.FrameNum;
|
|
|
- }
|
|
|
- else if (lastframeNum == e.FrameOut.FrameNum - 1)
|
|
|
+ if(isFrameRateLimit && frameRateLimit>0)
|
|
|
{
|
|
|
- lastframeNum = e.FrameOut.FrameNum;
|
|
|
+ TimeSpan elapsed = DateTime.Now - _lastFrame;
|
|
|
+ if (elapsed.TotalSeconds > minIntervalMs)
|
|
|
+ {
|
|
|
+ // 触发外部注册的事件
|
|
|
+ FrameGrabbedEvent?.Invoke(this, e);
|
|
|
+ _lastFrame = DateTime.Now;
|
|
|
+ }
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- //丢帧记录
|
|
|
- TxtLog.log(string.Format("lost frame: Width[{0}] , Height[{1}] , FrameNum[{2}] ,Frevous[{3}]",
|
|
|
- e.FrameOut.Image.Width, e.FrameOut.Image.Height, e.FrameOut.FrameNum, lastframeNum), 6);
|
|
|
- Console.WriteLine("lost frame: Width[{0}] , Height[{1}] , FrameNum[{2}] ,Frevous[{3}]",
|
|
|
- e.FrameOut.Image.Width, e.FrameOut.Image.Height, e.FrameOut.FrameNum, lastframeNum);
|
|
|
- lastframeNum = e.FrameOut.FrameNum;
|
|
|
+ // 触发外部注册的事件
|
|
|
+ FrameGrabbedEvent?.Invoke(this, e);
|
|
|
+ if (lastframeNum == -1)
|
|
|
+ {
|
|
|
+ lastframeNum = e.FrameOut.FrameNum;
|
|
|
+ }
|
|
|
+ else if (lastframeNum == e.FrameOut.FrameNum - 1)
|
|
|
+ {
|
|
|
+ lastframeNum = e.FrameOut.FrameNum;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //丢帧记录
|
|
|
+ TxtLog.log(string.Format("lost frame: Width[{0}] , Height[{1}] , FrameNum[{2}] ,Frevous[{3}]",
|
|
|
+ e.FrameOut.Image.Width, e.FrameOut.Image.Height, e.FrameOut.FrameNum, lastframeNum), 6);
|
|
|
+ Console.WriteLine("lost frame: Width[{0}] , Height[{1}] , FrameNum[{2}] ,Frevous[{3}]",
|
|
|
+ e.FrameOut.Image.Width, e.FrameOut.Image.Height, e.FrameOut.FrameNum, lastframeNum);
|
|
|
+ lastframeNum = e.FrameOut.FrameNum;
|
|
|
+ }
|
|
|
}
|
|
|
e.FrameOut.Dispose();
|
|
|
}
|