forked from Ken98045/On-Guard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AreaOfInterest.cs
164 lines (137 loc) · 5.19 KB
/
AreaOfInterest.cs
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
using System;
using System.Collections.Generic;
using System.Drawing;
namespace SAAI
{
[Serializable]
public enum AOIType
{
IgnoreObjects = 0,
Door,
GarageDoor,
Driveway,
PeopleWalking
}
[Serializable]
public enum MovementType
{
AnyActivity = 1,
Arrival,
Departure
}
[Serializable]
public enum ImageObjectType
{
Irrelevant,
People = 1,
Cars,
Trucks,
Motorcycles,
Bikes,
Animals,
Bears
}
/// <summary>
/// An Area of Interest is a key concept for the application. Objects found by the AI area
/// only "Interesting" if they are in an AreaOfInterest.
/// AreasOfInterest can also be used to define areas in which we ignore objects.
/// You can have as many areas as you like
/// </summary>
[Serializable]
public class AreaOfInterest : IDisposable
{
public string AOIName { get; set; } // The name to identify the area. Also sent in any email notifications
public AOIType AOIType { get; set; } // Ignore, Door, Garage Door, Driveway. Door has priority characteristincs
public MovementType MovementType { get; set; } // Not yet implemented. In the future you can optionally notify for objects moving to or away from the area
public List<ObjectCharacteristics> SearchCriteria { get; set; } // Defines the characteristic for each object type - confidence, overlap, minimum size, ...
public Rectangle AreaRect; // The area for the AOI, in original bitmap pixels, not screen pixels
public int OriginalXResolution { get; set; } // Because if the camera images change resolution we need to adjust the virtual area
public int OriginalYResolution { get; set; } // ""
public Point ZoneFocus { get; set; } // The point in the area used to determine motion to/from the MovementType - Always relative to the area
public AreaNotificationOption Notifications { get; set; } // URL and Email notifications, maybe others in the future
public Guid ID { get; } // a unique id for the area
public AreaOfInterest()
{
ID = Guid.NewGuid();
SearchCriteria = new List<ObjectCharacteristics>();
Notifications = new AreaNotificationOption();
}
public AreaOfInterest
(
Guid id,
string name,
AOIType areaType,
Rectangle areaRect,
int originalXResolution,
int originalYResolution,
MovementType movementType,
AreaNotificationOption notifications,
List<ObjectCharacteristics> searchCritera
)
{
ID = id;
AOIName = name;
AOIType = areaType;
AreaRect = areaRect;
OriginalXResolution = originalXResolution;
OriginalYResolution = originalYResolution;
MovementType = movementType;
Notifications = notifications;
SearchCriteria = searchCritera;
}
// Copy constructor for an area.
public AreaOfInterest(AreaOfInterest src)
{
ID = src.ID; //
AOIName = src.AOIName;
AOIType = src.AOIType;
AreaRect = src.AreaRect;
OriginalXResolution = src.OriginalXResolution;
OriginalYResolution = src.OriginalYResolution;
MovementType = src.MovementType;
Notifications = new AreaNotificationOption(src.Notifications);
SearchCriteria = new List<ObjectCharacteristics>(src.SearchCriteria);
}
// Get a rectangle that is adjusted according to the resolution when the area was created.
// The resolution of bitmaps actually processed may not be the same as the resolution when the area was created
public Rectangle GetRect()
{
Rectangle adjRect = new Rectangle(AreaRect.X, AreaRect.Y, AreaRect.Width, AreaRect.Height);
adjRect.X = (int)((double)AreaRect.X * ((double)(BitmapResolution.XResolution) / (double)(OriginalXResolution)));
adjRect.Y = (int)((double)AreaRect.Y * ((double)(BitmapResolution.YResolution) / (double)(OriginalYResolution)));
adjRect.Width = (int)((double)AreaRect.Width * ((double)(BitmapResolution.XResolution) / (double)OriginalXResolution));
adjRect.Height = (int)((double)AreaRect.Height * ((double)(BitmapResolution.YResolution) / (double)OriginalYResolution));
return adjRect;
}
public void SetRect(Rectangle rect)
{
}
public void AdjustRect(int xOffset, int yOffset)
{
double xRatio = (double)BitmapResolution.XResolution / (double)OriginalXResolution;
double yRatio = (double)BitmapResolution.YResolution / (double)OriginalYResolution;
AreaRect.X = AreaRect.X - (int)(xRatio * (double)xOffset);
AreaRect.Y = AreaRect.Y - (int)(yRatio * (double)yOffset);
}
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
if (disposing)
{
Notifications = null;
SearchCriteria = null;
}
disposedValue = true;
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
}
}