HandRecordManager.cs
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
using System;
using System.Collections.Generic;
using System.Drawing;
using TSA_V.Common;
namespace TSA_V.DeviceLibrary
{
public class HandRecordManager
{
/// <summary>
/// 开始统计时间
/// </summary>
private static DateTime startTime { get; set; } = DateTime.Now;
/// <summary>
/// 当前状态,0=无手势,>0有手势
/// </summary>
public static bool currHasPoint = false ;
private static DateTime currStartTime = DateTime.Now;
public static int recordCount = 0;
public static TimeSpan recordSpan = TimeSpan.Zero;
private static Rectangle currRectangle =new Rectangle (0,0,0,0);
private static void LoadRect()
{
try
{
string[] configs = Setting_NInit.Hand_RectConfig;
if (configs.Length == 4)
{
int x = Convert.ToInt32(configs[0]);
int y= Convert.ToInt32(configs[1]);
int w = Convert.ToInt32(configs[2]);
int h= Convert.ToInt32(configs[3]);
currRectangle=new Rectangle(x,y,w,h);
}
}
catch (Exception ex)
{
LogUtil.error("出错:" + ex.ToString());
}
}
public static void Reset()
{
LogUtil.info($"重置手势统计,当前已统计:{recordCount}次,共{recordSpan.TotalSeconds}秒,当前状态:{currHasPoint}");
//重置
startTime = DateTime.Now;
currHasPoint = false ;
currStartTime = DateTime.Now;
recordCount = 0;
recordSpan = TimeSpan.Zero;
}
public static void ProcessPoint(int pCount, List<List<int>> points)
{
try
{
if (currRectangle.Width <= 0 || currRectangle.Height <= 0)
{
LoadRect();
}
bool isHas = false;
if (pCount > 0 && pCount == points.Count)
{
foreach (List<int> point in points)
{
if (point.Count == 3)
{
int index = point[0];
int x = point[1];
int y = point[2];
if (x > currRectangle.X && x < currRectangle.X + currRectangle.Width && y > currRectangle.Y && y < currRectangle.Y + currRectangle.Height)
{
isHas = true;
break;
}
}
}
}
if (isHas)
{
if (currHasPoint)
{
return;
}
else
{
currHasPoint = true;
currStartTime = DateTime.Now;
}
}
else
{
if (currHasPoint)
{
TimeSpan span = DateTime.Now - currStartTime;
recordCount++;
recordSpan += span;
currHasPoint = false;
}
else
{
currHasPoint = false;
}
}
}
catch (Exception ex)
{
LogUtil.error("出错:" + ex.ToString());
}
}
}
}