-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
239 lines (209 loc) · 9.34 KB
/
MainWindow.xaml.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license.
//
// Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services
//
// Microsoft Cognitive Services (formerly Project Oxford) GitHub:
// https://github.com/Microsoft/Cognitive-Face-Windows
//
// Copyright (c) Microsoft Corporation
// All rights reserved.
//
// MIT License:
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System.ComponentModel;
using System.Net;
using System.Runtime.CompilerServices;
using System.Windows;
using Microsoft.ProjectOxford.Face.Controls;
using SampleUserControlLibrary;
namespace Microsoft.ProjectOxford.Face
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="MainWindow" /> class
/// </summary>
public MainWindow()
{
InitializeComponent();
ServicePointManager.DefaultConnectionLimit = 1000;
// You can use the next line to insert your own subscription key, instead of using UI to set license key.
this.ViewModel = new MainViewModel()
{
FaceDetectionDescription = "Locate faces in an image. You can pick an image by 'Choose Image'. Detected faces will be shown on the image by rectangles surrounding the face, and related attributes will be shown in a list.",
FaceVerificationDescription = "There are two demos in Face Verification sample.",
FacePersonVerificationDescription = "Face to person verification determines whether one face belongs to one person. You can pick an image folder containing one person's single face, and another single face image. Then click 'Verify' to get the verification result.",
FaceFaceVerificationDescription = "Face to Face Verification determines whether two faces belong to the same person. You can pick single face image, the detected face will be shown on the image. Then click 'Verify' to get the verification result.",
FaceGroupingDescription = "Put similar faces to same group according to appearance similarity. You can pick an image folder for grouping by 'Group', doing this will group all detected faces and shown under Grouping Result.",
FaceFindSimilarDescription = "Find similar faces for the query face from all the candidates. You can pick an image folder, and all detected faces inside the folder will be treated as candidate. Use 'Open Query Face' to pick the query faces. The result will be list as 'query face's thumbnail', 'similar faces' thumbnails with similarity ranked'. Both of 'MatchPerson' mode and 'MatchFace' mode results will be listed. 'MatchPerson' mode return the top candidate faces among those recognized as the same person with the query face, so if no candidate faces are recognized as the same person with the query face, no one will be returned, while 'MatchFace' mode returns the top candidate faces with highest similarity confidence without checking if the returned face belong to the same person with the query face.",
FaceIdentificationDescription = "Tell whom an input face belongs to given a tagged person database. Here we only handle tagged person database in following format: 1). One root folder. 2). Sub-folders are named as person's name. 3). Each person's images are put into their own sub-folder. Pick the root folder, then choose an image to identify, all faces will be shown on the image with the identified person's name.",
};
this.DataContext = this.ViewModel;
this._scenariosControl.SampleScenarioList = new Scenario[]
{
new Scenario()
{
PageClass = typeof(LiveFaceDetectionPage),
Title = "LIVE - Face Detection",
},
new Scenario()
{
PageClass = typeof(FaceDetectionPage),
Title = "Face Detection",
},
new Scenario()
{
PageClass = typeof(FaceFindSimilarPage),
Title = "Face Find Similar",
},
new Scenario()
{
PageClass = typeof(FaceGroupingPage),
Title = "Face Grouping",
},
new Scenario()
{
PageClass = typeof(FaceIdentificationPage),
Title = "Face Identification",
},
new Scenario()
{
PageClass = typeof(FaceVerificationPage),
Title = "Face Verification",
},
};
}
#endregion Constructors
#region Properties
/// <summary>
/// Gets view model instance for MainWindow
/// </summary>
public MainViewModel ViewModel
{
get; private set;
}
#endregion Properties
#region Methods
/// <summary>
/// Log message in main window log pane
/// </summary>
/// <param name="format">format string</param>
/// <param name="args">format arguments</param>
public static void Log(string format, params object[] args)
{
((MainWindow)Application.Current.MainWindow)._scenariosControl.Log(string.Format(format, args));
}
#endregion Methods
#region Nested Types
/// <summary>
/// View model for MainWindow, covers display image, text
/// </summary>
public class MainViewModel : INotifyPropertyChanged
{
#region Events
/// <summary>
/// Implements INotifyPropertyChanged interface
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
#endregion Events
#region Properties
/// <summary>
/// Gets or sets description of face detection
/// </summary>
public string FaceDetectionDescription
{
get;
set;
}
/// <summary>
/// Gets or sets description of face verification
/// </summary>
public string FaceVerificationDescription
{
get;
set;
}
/// <summary>
/// Gets or sets description of face to face verification
/// </summary>
public string FaceFaceVerificationDescription
{
get;
set;
}
/// <summary>
/// Gets or sets description of face to person verification
/// </summary>
public string FacePersonVerificationDescription
{
get;
set;
}
/// <summary>
/// Gets or sets description of face grouping
/// </summary>
public string FaceGroupingDescription
{
get;
set;
}
/// <summary>
/// Gets or sets description of find similar face
/// </summary>
public string FaceFindSimilarDescription
{
get;
set;
}
/// <summary>
/// Gets or sets description of identification
/// </summary>
public string FaceIdentificationDescription
{
get;
set;
}
#endregion Properties
#region Methods
/// <summary>
/// Helper function for INotifyPropertyChanged interface
/// </summary>
/// <typeparam name="T">Property type</typeparam>
/// <param name="caller">Property name</param>
private void OnPropertyChanged<T>([CallerMemberName]string caller = null)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(caller));
}
}
#endregion Methods
}
#endregion Nested Types
}
}