Remove deprecated Emotion API (#7)

Emotion API calls are now made through the Face API.
This commit is contained in:
Chris Thrasher 2018-04-10 20:37:05 -07:00 committed by GitHub
parent 6a5b59d1af
commit 05b7597ea1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 63 additions and 136 deletions

View file

@ -9,7 +9,6 @@ This sample contains a library, along with two applications, for analyzing video
1. Get API keys for the Vision APIs from [microsoft.com/cognitive][Sign-Up]. For video frame analysis, the applicable APIs are: 1. Get API keys for the Vision APIs from [microsoft.com/cognitive][Sign-Up]. For video frame analysis, the applicable APIs are:
- [Computer Vision API][] - [Computer Vision API][]
- [Emotion API][]
- [Face API][] - [Face API][]
2. Open the sample in Visual Studio 2015, build and run the sample applications: 2. Open the sample in Visual Studio 2015, build and run the sample applications:
- For BasicConsoleSample, the Face API key is hard-coded directly in [BasicConsoleSample/Program.cs](Windows/BasicConsoleSample/Program.cs). - For BasicConsoleSample, the Face API key is hard-coded directly in [BasicConsoleSample/Program.cs](Windows/BasicConsoleSample/Program.cs).
@ -18,7 +17,6 @@ This sample contains a library, along with two applications, for analyzing video
[Sign-Up]: https://www.microsoft.com/cognitive-services/en-us/sign-up [Sign-Up]: https://www.microsoft.com/cognitive-services/en-us/sign-up
[Computer Vision API]: https://www.microsoft.com/cognitive-services/en-us/computer-vision-api [Computer Vision API]: https://www.microsoft.com/cognitive-services/en-us/computer-vision-api
[Emotion API]: https://www.microsoft.com/cognitive-services/en-us/emotion-api
[Face API]: https://www.microsoft.com/cognitive-services/en-us/face-api [Face API]: https://www.microsoft.com/cognitive-services/en-us/face-api
## Using the VideoFrameAnalyzer Library ## Using the VideoFrameAnalyzer Library
@ -26,7 +24,7 @@ This sample contains a library, along with two applications, for analyzing video
You can start using the library with only a few lines of code: You can start using the library with only a few lines of code:
```csharp ```csharp
// Create Face API Client. // Create Face API Client.
FaceServiceClient faceClient = new FaceServiceClient("<subscription key>"); FaceServiceClient faceClient = new FaceServiceClient("<subscription key>","<api root>");
// Create grabber, with analysis type Face[]. // Create grabber, with analysis type Face[].
FrameGrabber<Face[]> grabber = new FrameGrabber<Face[]>(); FrameGrabber<Face[]> grabber = new FrameGrabber<Face[]>();
// Set up Face API call, which returns a Face[]. Simply encodes image and submits to Face API. // Set up Face API call, which returns a Face[]. Simply encodes image and submits to Face API.

View file

@ -40,8 +40,8 @@
<HintPath>..\packages\Microsoft.ProjectOxford.Common.1.0.324\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Common.dll</HintPath> <HintPath>..\packages\Microsoft.ProjectOxford.Common.1.0.324\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Common.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Microsoft.ProjectOxford.Face, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="Microsoft.ProjectOxford.Face, Version=1.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.ProjectOxford.Face.1.3.0\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Microsoft.ProjectOxford.Face.dll</HintPath> <HintPath>..\packages\Microsoft.ProjectOxford.Face.1.4.0\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Microsoft.ProjectOxford.Face.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">

View file

@ -4,7 +4,7 @@
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net452" /> <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net452" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net452" /> <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net452" />
<package id="Microsoft.ProjectOxford.Common" version="1.0.324" targetFramework="net452" /> <package id="Microsoft.ProjectOxford.Common" version="1.0.324" targetFramework="net452" />
<package id="Microsoft.ProjectOxford.Face" version="1.3.0" targetFramework="net452" /> <package id="Microsoft.ProjectOxford.Face" version="1.4.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" /> <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="OpenCvSharp3-AnyCPU" version="3.1.0.20160622" targetFramework="net452" /> <package id="OpenCvSharp3-AnyCPU" version="3.1.0.20160622" targetFramework="net452" />
</packages> </packages>

View file

@ -31,9 +31,9 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
using Microsoft.ProjectOxford.Emotion.Contract;
using System.Linq; using System.Linq;
using Microsoft.ProjectOxford.Face.Contract; using Microsoft.ProjectOxford.Face.Contract;
using Microsoft.ProjectOxford.Common.Contract;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -41,12 +41,12 @@ namespace LiveCameraSample
{ {
internal class Aggregation internal class Aggregation
{ {
public static Tuple<string, float> GetDominantEmotion(Microsoft.ProjectOxford.Common.Contract.EmotionScores scores) public static Tuple<string, float> GetDominantEmotion(EmotionScores scores)
{ {
return scores.ToRankedList().Select(kv => new Tuple<string, float>(kv.Key, kv.Value)).First(); return scores.ToRankedList().Select(kv => new Tuple<string, float>(kv.Key, kv.Value)).First();
} }
public static string SummarizeEmotion(Microsoft.ProjectOxford.Common.Contract.EmotionScores scores) public static string SummarizeEmotion(EmotionScores scores)
{ {
var bestEmotion = Aggregation.GetDominantEmotion(scores); var bestEmotion = Aggregation.GetDominantEmotion(scores);
return string.Format("{0}: {1:N1}", bestEmotion.Item1, bestEmotion.Item2); return string.Format("{0}: {1:N1}", bestEmotion.Item1, bestEmotion.Item2);

View file

@ -28,9 +28,6 @@
<setting name="FaceAPIKey" serializeAs="String"> <setting name="FaceAPIKey" serializeAs="String">
<value /> <value />
</setting> </setting>
<setting name="EmotionAPIKey" serializeAs="String">
<value />
</setting>
<setting name="VisionAPIKey" serializeAs="String"> <setting name="VisionAPIKey" serializeAs="String">
<value /> <value />
</setting> </setting>
@ -43,9 +40,6 @@
<setting name="FaceAPICallCount" serializeAs="String"> <setting name="FaceAPICallCount" serializeAs="String">
<value>0</value> <value>0</value>
</setting> </setting>
<setting name="EmotionAPICallCount" serializeAs="String">
<value>0</value>
</setting>
<setting name="VisionAPICallCount" serializeAs="String"> <setting name="VisionAPICallCount" serializeAs="String">
<value>0</value> <value>0</value>
</setting> </setting>

View file

@ -46,8 +46,8 @@
<HintPath>..\packages\Microsoft.ProjectOxford.Emotion.1.0.336\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Emotion.dll</HintPath> <HintPath>..\packages\Microsoft.ProjectOxford.Emotion.1.0.336\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Emotion.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Microsoft.ProjectOxford.Face, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="Microsoft.ProjectOxford.Face, Version=1.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.ProjectOxford.Face.1.3.0\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Microsoft.ProjectOxford.Face.dll</HintPath> <HintPath>..\packages\Microsoft.ProjectOxford.Face.1.4.0\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Microsoft.ProjectOxford.Face.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Microsoft.ProjectOxford.Vision, Version=1.0.393.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="Microsoft.ProjectOxford.Vision, Version=1.0.393.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">

View file

@ -49,22 +49,17 @@
<TextBox Margin="5" Grid.Row="0" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.FaceAPIKey, Mode=TwoWay}" /> <TextBox Margin="5" Grid.Row="0" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.FaceAPIKey, Mode=TwoWay}" />
<TextBlock Margin="5" Grid.Row="1" Grid.Column="0" Text="Face API Host:" /> <TextBlock Margin="5" Grid.Row="1" Grid.Column="0" Text="Face API Host:" />
<TextBox Margin="5" Grid.Row="1" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.FaceAPIHost, Mode=TwoWay}" /> <TextBox Margin="5" Grid.Row="1" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.FaceAPIHost, Mode=TwoWay}" />
<TextBlock Margin="5" Grid.Row="2" Grid.Column="0" Text="Emotion API Key:" /> <TextBlock Margin="5" Grid.Row="2" Grid.Column="0" Text="Vision API Key:" />
<TextBox Margin="5" Grid.Row="2" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.EmotionAPIKey, Mode=TwoWay}" /> <TextBox Margin="5" Grid.Row="2" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.VisionAPIKey, Mode=TwoWay}" />
<TextBlock Margin="5" Grid.Row="3" Grid.Column="0" Text="Emotion API Host:" /> <TextBlock Margin="5" Grid.Row="3" Grid.Column="0" Text="Vision API Host:" />
<TextBox Margin="5" Grid.Row="3" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.EmotionAPIHost, Mode=TwoWay}" /> <TextBox Margin="5" Grid.Row="3" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.VisionAPIHost, Mode=TwoWay}" />
<TextBlock Margin="5" Grid.Row="4" Grid.Column="0" Text="Vision API Key:" /> <TextBlock Margin="5" Grid.Row="4" Grid.ColumnSpan="2" TextWrapping="Wrap"><Run Text="Get API keys at "/><Hyperlink NavigateUri="http://www.microsoft.com/cognitive" RequestNavigate="Hyperlink_RequestNavigate"><Run Text="microsoft.com/cognitive"/></Hyperlink></TextBlock>
<TextBox Margin="5" Grid.Row="4" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.VisionAPIKey, Mode=TwoWay}" /> <TextBlock Margin="5" Grid.Row="5" Grid.Column="0" Text="API Call Interval:" />
<TextBlock Margin="5" Grid.Row="5" Grid.Column="0" Text="Vision API Host:" /> <TextBox Margin="5" Grid.Row="5" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.AnalysisInterval, Mode=TwoWay}" />
<TextBox Margin="5" Grid.Row="5" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.VisionAPIHost, Mode=TwoWay}" /> <TextBlock Margin="5" Grid.Row="6" Grid.ColumnSpan="2" TextWrapping="Wrap"><Run FontWeight="Bold" Text="Caution"/><Run Text=": Each video frame submitted to an API will count towards your transaction limit."/></TextBlock>
<TextBlock Margin="5" Grid.Row="6" Grid.ColumnSpan="2" TextWrapping="Wrap"><Run Text="Get API keys at "/><Hyperlink NavigateUri="http://www.microsoft.com/cognitive" RequestNavigate="Hyperlink_RequestNavigate"><Run Text="microsoft.com/cognitive"/></Hyperlink></TextBlock>
<TextBlock Margin="5" Grid.Row="7" Grid.Column="0" Text="API Call Interval:" />
<TextBox Margin="5" Grid.Row="7" Grid.Column="1" Text="{Binding Source={StaticResource Settings}, Path=Default.AnalysisInterval, Mode=TwoWay}" />
<TextBlock Margin="5" Grid.Row="8" Grid.ColumnSpan="2" TextWrapping="Wrap"><Run FontWeight="Bold" Text="Caution"/><Run Text=": Each video frame submitted to an API will count towards your transaction limit."/></TextBlock>
</Grid> </Grid>
<TextBlock Margin="5,0,5,5"> <TextBlock Margin="5,0,5,5">
<Run Text="Face API calls made = "/><Run Text="{Binding Source={StaticResource Settings}, Path=Default.FaceAPICallCount}"/><LineBreak /> <Run Text="Face API calls made = "/><Run Text="{Binding Source={StaticResource Settings}, Path=Default.FaceAPICallCount}"/><LineBreak />
<Run Text="Emotion API calls made = "/><Run Text="{Binding Source={StaticResource Settings}, Path=Default.EmotionAPICallCount}"/><LineBreak />
<Run Text="Vision API calls made = "/><Run Text="{Binding Source={StaticResource Settings}, Path=Default.VisionAPICallCount}"/> <Run Text="Vision API calls made = "/><Run Text="{Binding Source={StaticResource Settings}, Path=Default.VisionAPICallCount}"/>
</TextBlock> </TextBlock>
<CheckBox Margin="5" IsChecked="{Binding Source={StaticResource Settings}, Path=Default.AutoStopEnabled}" ContentStringFormat="Automatically stop after {0}" Content="{Binding Source={StaticResource Settings}, Path=Default.AutoStopTime}" /> <CheckBox Margin="5" IsChecked="{Binding Source={StaticResource Settings}, Path=Default.AutoStopEnabled}" ContentStringFormat="Automatically stop after {0}" Content="{Binding Source={StaticResource Settings}, Path=Default.AutoStopTime}" />

View file

@ -31,14 +31,6 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// //
using Microsoft.ProjectOxford.Emotion;
using Microsoft.ProjectOxford.Emotion.Contract;
using Microsoft.ProjectOxford.Face;
using Microsoft.ProjectOxford.Face.Contract;
using Microsoft.ProjectOxford.Vision;
using Newtonsoft.Json;
using OpenCvSharp;
using OpenCvSharp.Extensions;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -48,7 +40,13 @@ using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using Newtonsoft.Json;
using OpenCvSharp;
using OpenCvSharp.Extensions;
using VideoFrameAnalyzer; using VideoFrameAnalyzer;
using Common = Microsoft.ProjectOxford.Common;
using FaceAPI = Microsoft.ProjectOxford.Face;
using VisionAPI = Microsoft.ProjectOxford.Vision;
namespace LiveCameraSample namespace LiveCameraSample
{ {
@ -57,9 +55,8 @@ namespace LiveCameraSample
/// </summary> /// </summary>
public partial class MainWindow : System.Windows.Window public partial class MainWindow : System.Windows.Window
{ {
private EmotionServiceClient _emotionClient = null; private FaceAPI.FaceServiceClient _faceClient = null;
private FaceServiceClient _faceClient = null; private VisionAPI.VisionServiceClient _visionClient = null;
private VisionServiceClient _visionClient = null;
private readonly FrameGrabber<LiveCameraResult> _grabber = null; private readonly FrameGrabber<LiveCameraResult> _grabber = null;
private static readonly ImageEncodingParam[] s_jpegParams = { private static readonly ImageEncodingParam[] s_jpegParams = {
new ImageEncodingParam(ImwriteFlags.JpegQuality, 60) new ImageEncodingParam(ImwriteFlags.JpegQuality, 60)
@ -132,9 +129,9 @@ namespace LiveCameraSample
{ {
string apiName = ""; string apiName = "";
string message = e.Exception.Message; string message = e.Exception.Message;
var faceEx = e.Exception as FaceAPIException; var faceEx = e.Exception as FaceAPI.FaceAPIException;
var emotionEx = e.Exception as Microsoft.ProjectOxford.Common.ClientException; var emotionEx = e.Exception as Common.ClientException;
var visionEx = e.Exception as Microsoft.ProjectOxford.Vision.ClientException; var visionEx = e.Exception as VisionAPI.ClientException;
if (faceEx != null) if (faceEx != null)
{ {
apiName = "Face"; apiName = "Face";
@ -178,8 +175,11 @@ namespace LiveCameraSample
// Encode image. // Encode image.
var jpg = frame.Image.ToMemoryStream(".jpg", s_jpegParams); var jpg = frame.Image.ToMemoryStream(".jpg", s_jpegParams);
// Submit image to API. // Submit image to API.
var attrs = new List<FaceAttributeType> { FaceAttributeType.Age, var attrs = new List<FaceAPI.FaceAttributeType> {
FaceAttributeType.Gender, FaceAttributeType.HeadPose }; FaceAPI.FaceAttributeType.Age,
FaceAPI.FaceAttributeType.Gender,
FaceAPI.FaceAttributeType.HeadPose
};
var faces = await _faceClient.DetectAsync(jpg, returnFaceAttributes: attrs); var faces = await _faceClient.DetectAsync(jpg, returnFaceAttributes: attrs);
// Count the API call. // Count the API call.
Properties.Settings.Default.FaceAPICallCount++; Properties.Settings.Default.FaceAPICallCount++;
@ -196,44 +196,33 @@ namespace LiveCameraSample
// Encode image. // Encode image.
var jpg = frame.Image.ToMemoryStream(".jpg", s_jpegParams); var jpg = frame.Image.ToMemoryStream(".jpg", s_jpegParams);
// Submit image to API. // Submit image to API.
Emotion[] emotions = null; FaceAPI.Contract.Face[] faces = null;
// See if we have local face detections for this image. // See if we have local face detections for this image.
var localFaces = (OpenCvSharp.Rect[])frame.UserData; var localFaces = (OpenCvSharp.Rect[])frame.UserData;
if (localFaces == null) if (localFaces == null || localFaces.Count() > 0)
{ {
// If localFaces is null, we're not performing local face detection. // If localFaces is null, we're not performing local face detection.
// Use Cognigitve Services to do the face detection. // Use Cognigitve Services to do the face detection.
Properties.Settings.Default.EmotionAPICallCount++; Properties.Settings.Default.FaceAPICallCount++;
emotions = await _emotionClient.RecognizeAsync(jpg); faces = await _faceClient.DetectAsync(
} jpg,
else if (localFaces.Count() > 0) /* returnFaceId= */ false,
{ /* returnFaceLandmarks= */ false,
// If we have local face detections, we can call the API with them. new FaceAPI.FaceAttributeType[1] { FaceAPI.FaceAttributeType.Emotion });
// First, convert the OpenCvSharp rectangles.
var rects = localFaces.Select(
f => new Microsoft.ProjectOxford.Common.Rectangle
{
Left = f.Left,
Top = f.Top,
Width = f.Width,
Height = f.Height
});
Properties.Settings.Default.EmotionAPICallCount++;
emotions = await _emotionClient.RecognizeAsync(jpg, rects.ToArray());
} }
else else
{ {
// Local face detection found no faces; don't call Cognitive Services. // Local face detection found no faces; don't call Cognitive Services.
emotions = new Emotion[0]; faces = new FaceAPI.Contract.Face[0];
} }
// Output. // Output.
return new LiveCameraResult return new LiveCameraResult
{ {
Faces = emotions.Select(e => CreateFace(e.FaceRectangle)).ToArray(), Faces = faces.Select(e => CreateFace(e.FaceRectangle)).ToArray(),
// Extract emotion scores from results. // Extract emotion scores from results.
EmotionScores = emotions.Select(e => e.Scores).ToArray() EmotionScores = faces.Select(e => e.FaceAttributes.Emotion).ToArray()
}; };
} }
@ -376,13 +365,11 @@ namespace LiveCameraSample
// Clean leading/trailing spaces in API keys. // Clean leading/trailing spaces in API keys.
Properties.Settings.Default.FaceAPIKey = Properties.Settings.Default.FaceAPIKey.Trim(); Properties.Settings.Default.FaceAPIKey = Properties.Settings.Default.FaceAPIKey.Trim();
Properties.Settings.Default.EmotionAPIKey = Properties.Settings.Default.EmotionAPIKey.Trim();
Properties.Settings.Default.VisionAPIKey = Properties.Settings.Default.VisionAPIKey.Trim(); Properties.Settings.Default.VisionAPIKey = Properties.Settings.Default.VisionAPIKey.Trim();
// Create API clients. // Create API clients.
_faceClient = new FaceServiceClient(Properties.Settings.Default.FaceAPIKey, Properties.Settings.Default.FaceAPIHost); _faceClient = new FaceAPI.FaceServiceClient(Properties.Settings.Default.FaceAPIKey, Properties.Settings.Default.FaceAPIHost);
_emotionClient = new EmotionServiceClient(Properties.Settings.Default.EmotionAPIKey, Properties.Settings.Default.EmotionAPIHost); _visionClient = new VisionAPI.VisionServiceClient(Properties.Settings.Default.VisionAPIKey, Properties.Settings.Default.VisionAPIHost);
_visionClient = new VisionServiceClient(Properties.Settings.Default.VisionAPIKey, Properties.Settings.Default.VisionAPIHost);
// How often to analyze. // How often to analyze.
_grabber.TriggerAnalysisOnInterval(Properties.Settings.Default.AnalysisInterval); _grabber.TriggerAnalysisOnInterval(Properties.Settings.Default.AnalysisInterval);
@ -418,11 +405,11 @@ namespace LiveCameraSample
e.Handled = true; e.Handled = true;
} }
private Face CreateFace(FaceRectangle rect) private FaceAPI.Contract.Face CreateFace(FaceAPI.Contract.FaceRectangle rect)
{ {
return new Face return new FaceAPI.Contract.Face
{ {
FaceRectangle = new FaceRectangle FaceRectangle = new FaceAPI.Contract.FaceRectangle
{ {
Left = rect.Left, Left = rect.Left,
Top = rect.Top, Top = rect.Top,
@ -432,11 +419,11 @@ namespace LiveCameraSample
}; };
} }
private Face CreateFace(Microsoft.ProjectOxford.Vision.Contract.FaceRectangle rect) private FaceAPI.Contract.Face CreateFace(VisionAPI.Contract.FaceRectangle rect)
{ {
return new Face return new FaceAPI.Contract.Face
{ {
FaceRectangle = new FaceRectangle FaceRectangle = new FaceAPI.Contract.FaceRectangle
{ {
Left = rect.Left, Left = rect.Left,
Top = rect.Top, Top = rect.Top,
@ -446,11 +433,11 @@ namespace LiveCameraSample
}; };
} }
private Face CreateFace(Microsoft.ProjectOxford.Common.Rectangle rect) private FaceAPI.Contract.Face CreateFace(Common.Rectangle rect)
{ {
return new Face return new FaceAPI.Contract.Face
{ {
FaceRectangle = new FaceRectangle FaceRectangle = new FaceAPI.Contract.FaceRectangle
{ {
Left = rect.Left, Left = rect.Left,
Top = rect.Top, Top = rect.Top,
@ -460,7 +447,7 @@ namespace LiveCameraSample
}; };
} }
private void MatchAndReplaceFaceRectangles(Face[] faces, OpenCvSharp.Rect[] clientRects) private void MatchAndReplaceFaceRectangles(FaceAPI.Contract.Face[] faces, OpenCvSharp.Rect[] clientRects)
{ {
// Use a simple heuristic for matching the client-side faces to the faces in the // Use a simple heuristic for matching the client-side faces to the faces in the
// results. Just sort both lists left-to-right, and assume a 1:1 correspondence. // results. Just sort both lists left-to-right, and assume a 1:1 correspondence.
@ -482,7 +469,7 @@ namespace LiveCameraSample
{ {
// convert from OpenCvSharp rectangles // convert from OpenCvSharp rectangles
OpenCvSharp.Rect r = sortedClientRects[i]; OpenCvSharp.Rect r = sortedClientRects[i];
sortedResultFaces[i].FaceRectangle = new FaceRectangle { Left = r.Left, Top = r.Top, Width = r.Width, Height = r.Height }; sortedResultFaces[i].FaceRectangle = new FaceAPI.Contract.FaceRectangle { Left = r.Left, Top = r.Top, Width = r.Width, Height = r.Height };
} }
} }
} }

View file

@ -14,9 +14,9 @@ namespace LiveCameraSample.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
public static Settings Default { public static Settings Default {
get { get {
return defaultInstance; return defaultInstance;
@ -35,18 +35,6 @@ namespace LiveCameraSample.Properties {
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string EmotionAPIKey {
get {
return ((string)(this["EmotionAPIKey"]));
}
set {
this["EmotionAPIKey"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")] [global::System.Configuration.DefaultSettingValueAttribute("")]
@ -95,18 +83,6 @@ namespace LiveCameraSample.Properties {
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")]
public int EmotionAPICallCount {
get {
return ((int)(this["EmotionAPICallCount"]));
}
set {
this["EmotionAPICallCount"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("0")] [global::System.Configuration.DefaultSettingValueAttribute("0")]
@ -152,18 +128,6 @@ namespace LiveCameraSample.Properties {
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("https://westus.api.cognitive.microsoft.com/emotion/v1.0")]
public string EmotionAPIHost {
get {
return ((string)(this["EmotionAPIHost"]));
}
set {
this["EmotionAPIHost"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()] [global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("https://westus.api.cognitive.microsoft.com/vision/v1.0")] [global::System.Configuration.DefaultSettingValueAttribute("https://westus.api.cognitive.microsoft.com/vision/v1.0")]

View file

@ -5,9 +5,6 @@
<Setting Name="FaceAPIKey" Type="System.String" Scope="User"> <Setting Name="FaceAPIKey" Type="System.String" Scope="User">
<Value Profile="(Default)" /> <Value Profile="(Default)" />
</Setting> </Setting>
<Setting Name="EmotionAPIKey" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="VisionAPIKey" Type="System.String" Scope="User"> <Setting Name="VisionAPIKey" Type="System.String" Scope="User">
<Value Profile="(Default)" /> <Value Profile="(Default)" />
</Setting> </Setting>
@ -20,9 +17,6 @@
<Setting Name="FaceAPICallCount" Type="System.Int32" Scope="User"> <Setting Name="FaceAPICallCount" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value> <Value Profile="(Default)">0</Value>
</Setting> </Setting>
<Setting Name="EmotionAPICallCount" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
<Setting Name="VisionAPICallCount" Type="System.Int32" Scope="User"> <Setting Name="VisionAPICallCount" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value> <Value Profile="(Default)">0</Value>
</Setting> </Setting>
@ -35,9 +29,6 @@
<Setting Name="FaceAPIHost" Type="System.String" Scope="User"> <Setting Name="FaceAPIHost" Type="System.String" Scope="User">
<Value Profile="(Default)">https://westus.api.cognitive.microsoft.com/face/v1.0</Value> <Value Profile="(Default)">https://westus.api.cognitive.microsoft.com/face/v1.0</Value>
</Setting> </Setting>
<Setting Name="EmotionAPIHost" Type="System.String" Scope="User">
<Value Profile="(Default)">https://westus.api.cognitive.microsoft.com/emotion/v1.0</Value>
</Setting>
<Setting Name="VisionAPIHost" Type="System.String" Scope="User"> <Setting Name="VisionAPIHost" Type="System.String" Scope="User">
<Value Profile="(Default)">https://westus.api.cognitive.microsoft.com/vision/v1.0</Value> <Value Profile="(Default)">https://westus.api.cognitive.microsoft.com/vision/v1.0</Value>
</Setting> </Setting>

View file

@ -41,8 +41,7 @@ using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using Microsoft.ProjectOxford.Common.Contract; using Microsoft.ProjectOxford.Common.Contract;
using Microsoft.ProjectOxford.Emotion.Contract; using FaceAPI = Microsoft.ProjectOxford.Face.Contract;
using Microsoft.ProjectOxford.Face.Contract;
using Microsoft.ProjectOxford.Vision.Contract; using Microsoft.ProjectOxford.Vision.Contract;
namespace LiveCameraSample namespace LiveCameraSample
@ -102,7 +101,7 @@ namespace LiveCameraSample
return DrawOverlay(baseImage, drawAction); return DrawOverlay(baseImage, drawAction);
} }
public static BitmapSource DrawFaces(BitmapSource baseImage, Microsoft.ProjectOxford.Face.Contract.Face[] faces, EmotionScores[] emotionScores, string[] celebName) public static BitmapSource DrawFaces(BitmapSource baseImage, FaceAPI.Face[] faces, EmotionScores[] emotionScores, string[] celebName)
{ {
if (faces == null) if (faces == null)
{ {

View file

@ -4,8 +4,7 @@
<package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net452" /> <package id="Microsoft.Bcl.Build" version="1.0.21" targetFramework="net452" />
<package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net452" /> <package id="Microsoft.Net.Http" version="2.2.29" targetFramework="net452" />
<package id="Microsoft.ProjectOxford.Common" version="1.0.324" targetFramework="net452" /> <package id="Microsoft.ProjectOxford.Common" version="1.0.324" targetFramework="net452" />
<package id="Microsoft.ProjectOxford.Emotion" version="1.0.336" targetFramework="net452" /> <package id="Microsoft.ProjectOxford.Face" version="1.4.0" targetFramework="net452" />
<package id="Microsoft.ProjectOxford.Face" version="1.3.0" targetFramework="net452" />
<package id="Microsoft.ProjectOxford.Vision" version="1.0.393" targetFramework="net452" /> <package id="Microsoft.ProjectOxford.Vision" version="1.0.393" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" /> <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="OpenCvSharp3-AnyCPU" version="3.1.0.20160622" targetFramework="net452" /> <package id="OpenCvSharp3-AnyCPU" version="3.1.0.20160622" targetFramework="net452" />

View file

@ -90,7 +90,7 @@ namespace VideoFrameAnalyzer
/// <value> The analysis function. </value> /// <value> The analysis function. </value>
/// <example> This example shows how to provide an analysis function using a lambda expression. /// <example> This example shows how to provide an analysis function using a lambda expression.
/// <code> /// <code>
/// var client = new EmotionServiceClient("subscription key"); /// var client = new FaceServiceClient("subscription key", "api root");
/// var grabber = new FrameGrabber(); /// var grabber = new FrameGrabber();
/// grabber.AnalysisFunction = async (frame) =&gt; { return await client.RecognizeAsync(frame.Image.ToMemoryStream(".jpg")); }; /// grabber.AnalysisFunction = async (frame) =&gt; { return await client.RecognizeAsync(frame.Image.ToMemoryStream(".jpg")); };
/// </code></example> /// </code></example>