├── dxcafe1.png ├── dxcafe2.png ├── ml model.png ├── dxcafe ├── images │ ├── b.jpg │ ├── m.jpg │ ├── y.jpg │ ├── cafe.jpg │ ├── cafe.png │ ├── background.png │ └── noperson.jpg ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── App.xaml ├── App.xaml.cs ├── App.config ├── packages.config ├── LiveCameraResult.cs ├── ScoredMenu.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs └── dxcafe.csproj ├── VideoFrameAnalyzer ├── packages.config ├── ConcurrentLogger.cs ├── VideoFrame.cs ├── Properties │ └── AssemblyInfo.cs ├── VideoFrameAnalyzer.csproj └── FrameGrabber.cs ├── ServiceHelpers ├── app.config ├── packages.config ├── ErrorTrackingHelper.cs ├── Properties │ └── AssemblyInfo.cs ├── CoreUtil.cs ├── PhotoEvent.cs ├── EmotionServiceHelper.cs ├── ServiceHelpers.csproj ├── BingSearchHelper.cs ├── TextAnalyticsHelper.cs ├── FaceListManager.cs ├── FaceServiceHelper.cs └── ImageAnalyzer.cs ├── readme.md ├── .gitattributes ├── .gitignore └── dxcafe.sln /dxcafe1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/options/dxcafe/master/dxcafe1.png -------------------------------------------------------------------------------- /dxcafe2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/options/dxcafe/master/dxcafe2.png -------------------------------------------------------------------------------- /ml model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/options/dxcafe/master/ml model.png -------------------------------------------------------------------------------- /dxcafe/images/b.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/options/dxcafe/master/dxcafe/images/b.jpg -------------------------------------------------------------------------------- /dxcafe/images/m.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/options/dxcafe/master/dxcafe/images/m.jpg -------------------------------------------------------------------------------- /dxcafe/images/y.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/options/dxcafe/master/dxcafe/images/y.jpg -------------------------------------------------------------------------------- /dxcafe/images/cafe.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/options/dxcafe/master/dxcafe/images/cafe.jpg -------------------------------------------------------------------------------- /dxcafe/images/cafe.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/options/dxcafe/master/dxcafe/images/cafe.png -------------------------------------------------------------------------------- /dxcafe/images/background.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/options/dxcafe/master/dxcafe/images/background.png -------------------------------------------------------------------------------- /dxcafe/images/noperson.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/options/dxcafe/master/dxcafe/images/noperson.jpg -------------------------------------------------------------------------------- /dxcafe/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /VideoFrameAnalyzer/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /dxcafe/App.xaml: -------------------------------------------------------------------------------- 1 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /dxcafe/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace dxcafe 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ServiceHelpers/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /dxcafe/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ServiceHelpers/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /dxcafe/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /dxcafe/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace dxcafe.Properties 12 | { 13 | 14 | 15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] 17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase 18 | { 19 | 20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 21 | 22 | public static Settings Default 23 | { 24 | get 25 | { 26 | return defaultInstance; 27 | } 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # DXCafe : *Cognitive Kiosk* 2 | *This application was developed during Korea DX ISV Team Hackfest of Microsoft Korea.* 3 | 4 | I have developed this applications using a variety of Microsoft technologies based on the intent of the event, 5 | 6 | ## The scenarios is: 7 | * DXCafe is a café that sells a variety of coffees. 8 | * Behind the existing ordering method, Now, the customer can order a coffee DXCafe kiosk system. 9 | * This automatically, recognize the user's face, and recommend the menu based on the previous order history. 10 | * When the day ends, the order list is delivered to the manager. 11 | 12 | ## This application was developed using the following technologies: 13 | * Client Application: Use **WPF**. 14 | * Face Recognition: Use **Cognitive Service** to distinguish users face compared to previously registered faces. 15 | * Menu Recommendation: Use the learned **Azure ML** expectation Model using the user's previous order information. 16 | * REST API Hosting : **Azure App Service** is used to execute Azure ML service 17 | * Ordering Information: Workflow is configured using **Microsoft PowerApp** and **Microsoft Flow**. 18 | 19 | ## Screenshot 20 | 21 | ![Intro](https://github.com/options/dxcafe/blob/master/dxcafe1.png) 22 | ![Order](https://github.com/options/dxcafe/blob/master/dxcafe2.png) 23 | 24 | ## Azure ML Expectation Model 25 | ![Azure Model](https://github.com/options/dxcafe/blob/master/ml%20model.png) 26 | -------------------------------------------------------------------------------- /dxcafe/LiveCameraResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using System.Collections.Generic; 36 | using System.Linq; 37 | using System.Text; 38 | using System.Threading.Tasks; 39 | 40 | namespace dxcafe 41 | { 42 | // Class to hold all possible result types. 43 | public class LiveCameraResult 44 | { 45 | public Microsoft.ProjectOxford.Face.Contract.Face[] Faces { get; set; } = null; 46 | public Microsoft.ProjectOxford.Emotion.Contract.Scores[] EmotionScores { get; set; } = null; 47 | public string[] CelebrityNames { get; set; } = null; 48 | public Microsoft.ProjectOxford.Vision.Contract.Tag[] Tags { get; set; } = null; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ServiceHelpers/ErrorTrackingHelper.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using System.Collections.Generic; 36 | using System.Linq; 37 | using System.Text; 38 | using System.Threading.Tasks; 39 | 40 | namespace ServiceHelpers 41 | { 42 | public static class ErrorTrackingHelper 43 | { 44 | // callbacks for exception tracking 45 | public static Action TrackException { get; set; } 46 | = (exception, message) => { }; 47 | 48 | // callbacks for blocking UI error message 49 | public static Func GenericApiCallExceptionHandler { get; set; } 50 | = (ex, errorTitle) => Task.FromResult(0); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /dxcafe/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Resources; 3 | using System.Runtime.CompilerServices; 4 | using System.Runtime.InteropServices; 5 | using System.Windows; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("dxcafe")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("dxcafe")] 15 | [assembly: AssemblyCopyright("Copyright © 2016")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | //In order to begin building localizable applications, set 25 | //CultureYouAreCodingWith in your .csproj file 26 | //inside a . For example, if you are using US english 27 | //in your source files, set the to en-US. Then uncomment 28 | //the NeutralResourceLanguage attribute below. Update the "en-US" in 29 | //the line below to match the UICulture setting in the project file. 30 | 31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)] 32 | 33 | 34 | [assembly: ThemeInfo( 35 | ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 36 | //(used if a resource is not found in the page, 37 | // or application resource dictionaries) 38 | ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 39 | //(used if a resource is not found in the page, 40 | // app, or any theme specific resource dictionaries) 41 | )] 42 | 43 | 44 | // Version information for an assembly consists of the following four values: 45 | // 46 | // Major Version 47 | // Minor Version 48 | // Build Number 49 | // Revision 50 | // 51 | // You can specify all the values or you can default the Build and Revision Numbers 52 | // by using the '*' as shown below: 53 | // [assembly: AssemblyVersion("1.0.*")] 54 | [assembly: AssemblyVersion("1.0.0.0")] 55 | [assembly: AssemblyFileVersion("1.0.0.0")] 56 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /ServiceHelpers/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System.Resources; 35 | using System.Reflection; 36 | using System.Runtime.CompilerServices; 37 | using System.Runtime.InteropServices; 38 | 39 | // General Information about an assembly is controlled through the following 40 | // set of attributes. Change these attribute values to modify the information 41 | // associated with an assembly. 42 | [assembly: AssemblyTitle("ServiceHelpers")] 43 | [assembly: AssemblyDescription("")] 44 | [assembly: AssemblyConfiguration("")] 45 | [assembly: AssemblyCompany("")] 46 | [assembly: AssemblyProduct("ServiceHelpers")] 47 | [assembly: AssemblyCopyright("Copyright © 2016")] 48 | [assembly: AssemblyTrademark("")] 49 | [assembly: AssemblyCulture("")] 50 | [assembly: NeutralResourcesLanguage("en")] 51 | 52 | // Version information for an assembly consists of the following four values: 53 | // 54 | // Major Version 55 | // Minor Version 56 | // Build Number 57 | // Revision 58 | // 59 | // You can specify all the values or you can default the Build and Revision Numbers 60 | // by using the '*' as shown below: 61 | // [assembly: AssemblyVersion("1.0.*")] 62 | [assembly: AssemblyVersion("1.0.0.0")] 63 | [assembly: AssemblyFileVersion("1.0.0.0")] 64 | -------------------------------------------------------------------------------- /VideoFrameAnalyzer/ConcurrentLogger.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using System.Collections.Concurrent; 36 | using System.Threading; 37 | using System.Threading.Tasks; 38 | 39 | namespace VideoFrameAnalyzer 40 | { 41 | public static class ConcurrentLogger 42 | { 43 | private readonly static SemaphoreSlim s_printMutex = new SemaphoreSlim(1); 44 | private readonly static BlockingCollection s_messageQueue = new BlockingCollection(); 45 | 46 | public static void WriteLine(string message) 47 | { 48 | var timestamp = DateTime.Now; 49 | // Push the message on the queue 50 | s_messageQueue.Add(timestamp.ToString("o") + ": " + message); 51 | // Start a new task that will dequeue one message and print it. The tasks will not 52 | // necessarily run in order, but since each task just takes the oldest message and 53 | // prints it, the messages will print in order. 54 | Task.Run(async () => 55 | { 56 | // Wait to get access to the queue. 57 | await s_printMutex.WaitAsync(); 58 | try 59 | { 60 | string msg = s_messageQueue.Take(); 61 | Console.WriteLine(msg); 62 | } 63 | finally 64 | { 65 | s_printMutex.Release(); 66 | } 67 | }); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /dxcafe/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace dxcafe.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("dxcafe.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /VideoFrameAnalyzer/VideoFrame.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System; 35 | using OpenCvSharp; 36 | 37 | namespace VideoFrameAnalyzer 38 | { 39 | /// Metadata for a VideoFrame. 40 | public struct VideoFrameMetadata 41 | { 42 | public DateTime Timestamp; 43 | public int Index; 44 | } 45 | 46 | /// A video frame produced by the . 47 | /// This class encapsulates the image, any metadata, and also allows the user to attach 48 | /// some arbitrary data to each frame as it flows through the pipeline. 49 | public class VideoFrame 50 | { 51 | /// Constructor. 52 | /// The image captured by the camera. 53 | /// The metadata. 54 | public VideoFrame(Mat image, VideoFrameMetadata metadata) 55 | { 56 | Image = image; 57 | Metadata = metadata; 58 | } 59 | 60 | /// Gets the image for the frame. 61 | /// The image. 62 | public Mat Image { get; } 63 | 64 | /// Gets the frame's metadata. 65 | /// The metadata. 66 | public VideoFrameMetadata Metadata { get; } 67 | 68 | /// Gets or sets the frame's "user data". 69 | /// Any additional data that the user would like to attach to a video frame. 70 | public object UserData { get; set; } = null; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /VideoFrameAnalyzer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using System.Reflection; 35 | using System.Runtime.CompilerServices; 36 | using System.Runtime.InteropServices; 37 | 38 | // General Information about an assembly is controlled through the following 39 | // set of attributes. Change these attribute values to modify the information 40 | // associated with an assembly. 41 | [assembly: AssemblyTitle("VideoFrameAnalyzer")] 42 | [assembly: AssemblyDescription("")] 43 | [assembly: AssemblyConfiguration("")] 44 | [assembly: AssemblyCompany("")] 45 | [assembly: AssemblyProduct("VideoFrameAnalyzer")] 46 | [assembly: AssemblyCopyright("Copyright \u00A9 2016")] 47 | [assembly: AssemblyTrademark("")] 48 | [assembly: AssemblyCulture("")] 49 | 50 | // Setting ComVisible to false makes the types in this assembly not visible 51 | // to COM components. If you need to access a type in this assembly from 52 | // COM, set the ComVisible attribute to true on that type. 53 | [assembly: ComVisible(false)] 54 | 55 | // The following GUID is for the ID of the typelib if this project is exposed to COM 56 | [assembly: Guid("bec7da78-c953-4a72-924f-2749d1f9f18b")] 57 | 58 | // Version information for an assembly consists of the following four values: 59 | // 60 | // Major Version 61 | // Minor Version 62 | // Build Number 63 | // Revision 64 | // 65 | // You can specify all the values or you can default the Build and Revision Numbers 66 | // by using the '*' as shown below: 67 | // [assembly: AssemblyVersion("1.0.*")] 68 | [assembly: AssemblyVersion("1.0.0.0")] 69 | [assembly: AssemblyFileVersion("1.0.0.0")] 70 | -------------------------------------------------------------------------------- /ServiceHelpers/CoreUtil.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using Microsoft.ProjectOxford.Common; 35 | using Microsoft.ProjectOxford.Face; 36 | using System; 37 | using System.Collections.Generic; 38 | using System.IO; 39 | using System.Linq; 40 | using System.Threading.Tasks; 41 | using Microsoft.ProjectOxford.Face.Contract; 42 | using Microsoft.ProjectOxford.Emotion.Contract; 43 | 44 | namespace ServiceHelpers 45 | { 46 | public class CoreUtil 47 | { 48 | public static uint MinDetectableFaceCoveragePercentage = 0; 49 | 50 | public static bool IsFaceBigEnoughForDetection(int faceHeight, int imageHeight) 51 | { 52 | if (imageHeight == 0) 53 | { 54 | // sometimes we don't know the size of the image, so we assume the face is big enough 55 | return true; 56 | } 57 | 58 | double faceHeightPercentage = 100 * ((double)faceHeight / imageHeight); 59 | 60 | return faceHeightPercentage >= MinDetectableFaceCoveragePercentage; 61 | } 62 | 63 | public static Emotion FindFaceClosestToRegion(IEnumerable emotion, FaceRectangle region) 64 | { 65 | return emotion?.Where(e => CoreUtil.AreFacesPotentiallyTheSame(e.FaceRectangle, region)) 66 | .OrderBy(e => Math.Abs(region.Left - e.FaceRectangle.Left) + Math.Abs(region.Top - e.FaceRectangle.Top)).FirstOrDefault(); 67 | } 68 | 69 | public static bool AreFacesPotentiallyTheSame(Rectangle face1, FaceRectangle face2) 70 | { 71 | return AreFacesPotentiallyTheSame((int)face1.Left, (int)face1.Top, (int)face1.Width, (int)face1.Height, face2.Left, face2.Top, face2.Width, face2.Height); 72 | } 73 | 74 | public static bool AreFacesPotentiallyTheSame(int face1X, int face1Y, int face1Width, int face1Height, 75 | int face2X, int face2Y, int face2Width, int face2Height) 76 | { 77 | double distanceThresholdFactor = 1; 78 | double sizeThresholdFactor = 0.5; 79 | 80 | // See if faces are close enough from each other to be considered the "same" 81 | if (Math.Abs(face1X - face2X) <= face1Width * distanceThresholdFactor && 82 | Math.Abs(face1Y - face2Y) <= face1Height * distanceThresholdFactor) 83 | { 84 | // See if faces are shaped similarly enough to be considered the "same" 85 | if (Math.Abs(face1Width - face2Width) <= face1Width * sizeThresholdFactor && 86 | Math.Abs(face1Height - face2Height) <= face1Height * sizeThresholdFactor) 87 | { 88 | return true; 89 | } 90 | } 91 | 92 | return false; 93 | } 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | -------------------------------------------------------------------------------- /dxcafe.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dxcafe", "dxcafe\dxcafe.csproj", "{98D40BAC-E627-4402-8835-8B2B20B6BA3B}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceHelpers", "ServiceHelpers\ServiceHelpers.csproj", "{5D9320AF-A9E4-48E3-89BC-9F7F0954B298}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VideoFrameAnalyzer", "VideoFrameAnalyzer\VideoFrameAnalyzer.csproj", "{BEC7DA78-C953-4A72-924F-2749D1F9F18B}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0C2579C4-B143-402A-83B1-590F61AA2F03}" 13 | ProjectSection(SolutionItems) = preProject 14 | readme.md = readme.md 15 | EndProjectSection 16 | EndProject 17 | Global 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Any CPU = Debug|Any CPU 20 | Debug|ARM = Debug|ARM 21 | Debug|x64 = Debug|x64 22 | Debug|x86 = Debug|x86 23 | Release|Any CPU = Release|Any CPU 24 | Release|ARM = Release|ARM 25 | Release|x64 = Release|x64 26 | Release|x86 = Release|x86 27 | EndGlobalSection 28 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 29 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 30 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Debug|Any CPU.Build.0 = Debug|Any CPU 31 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Debug|ARM.ActiveCfg = Debug|Any CPU 32 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Debug|ARM.Build.0 = Debug|Any CPU 33 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Debug|x64.ActiveCfg = Debug|Any CPU 34 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Debug|x64.Build.0 = Debug|Any CPU 35 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Debug|x86.ActiveCfg = Debug|Any CPU 36 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Debug|x86.Build.0 = Debug|Any CPU 37 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Release|Any CPU.ActiveCfg = Release|Any CPU 38 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Release|Any CPU.Build.0 = Release|Any CPU 39 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Release|ARM.ActiveCfg = Release|Any CPU 40 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Release|ARM.Build.0 = Release|Any CPU 41 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Release|x64.ActiveCfg = Release|Any CPU 42 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Release|x64.Build.0 = Release|Any CPU 43 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Release|x86.ActiveCfg = Release|Any CPU 44 | {98D40BAC-E627-4402-8835-8B2B20B6BA3B}.Release|x86.Build.0 = Release|Any CPU 45 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 46 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Debug|Any CPU.Build.0 = Debug|Any CPU 47 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Debug|ARM.ActiveCfg = Debug|Any CPU 48 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Debug|ARM.Build.0 = Debug|Any CPU 49 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Debug|x64.ActiveCfg = Debug|Any CPU 50 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Debug|x64.Build.0 = Debug|Any CPU 51 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Debug|x86.ActiveCfg = Debug|Any CPU 52 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Debug|x86.Build.0 = Debug|Any CPU 53 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Release|Any CPU.ActiveCfg = Release|Any CPU 54 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Release|Any CPU.Build.0 = Release|Any CPU 55 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Release|ARM.ActiveCfg = Release|Any CPU 56 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Release|ARM.Build.0 = Release|Any CPU 57 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Release|x64.ActiveCfg = Release|Any CPU 58 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Release|x64.Build.0 = Release|Any CPU 59 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Release|x86.ActiveCfg = Release|Any CPU 60 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298}.Release|x86.Build.0 = Release|Any CPU 61 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 62 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Debug|Any CPU.Build.0 = Debug|Any CPU 63 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Debug|ARM.ActiveCfg = Debug|Any CPU 64 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Debug|ARM.Build.0 = Debug|Any CPU 65 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Debug|x64.ActiveCfg = Debug|Any CPU 66 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Debug|x64.Build.0 = Debug|Any CPU 67 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Debug|x86.ActiveCfg = Debug|Any CPU 68 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Debug|x86.Build.0 = Debug|Any CPU 69 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Release|Any CPU.ActiveCfg = Release|Any CPU 70 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Release|Any CPU.Build.0 = Release|Any CPU 71 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Release|ARM.ActiveCfg = Release|Any CPU 72 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Release|ARM.Build.0 = Release|Any CPU 73 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Release|x64.ActiveCfg = Release|Any CPU 74 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Release|x64.Build.0 = Release|Any CPU 75 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Release|x86.ActiveCfg = Release|Any CPU 76 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B}.Release|x86.Build.0 = Release|Any CPU 77 | EndGlobalSection 78 | GlobalSection(SolutionProperties) = preSolution 79 | HideSolutionNode = FALSE 80 | EndGlobalSection 81 | EndGlobal 82 | -------------------------------------------------------------------------------- /VideoFrameAnalyzer/VideoFrameAnalyzer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Debug 7 | AnyCPU 8 | {BEC7DA78-C953-4A72-924F-2749D1F9F18B} 9 | Library 10 | Properties 11 | VideoFrameAnalyzer 12 | VideoFrameAnalyzer 13 | v4.5.2 14 | 512 15 | 16 | 17 | 18 | 19 | true 20 | full 21 | false 22 | bin\Debug\ 23 | DEBUG;TRACE 24 | prompt 25 | 4 26 | 27 | 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | 35 | 36 | 37 | ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll 38 | True 39 | 40 | 41 | ..\packages\OpenCvSharp3-AnyCPU.3.1.0.20160622\lib\net45\OpenCvSharp.dll 42 | True 43 | 44 | 45 | ..\packages\OpenCvSharp3-AnyCPU.3.1.0.20160622\lib\net45\OpenCvSharp.Blob.dll 46 | True 47 | 48 | 49 | ..\packages\OpenCvSharp3-AnyCPU.3.1.0.20160622\lib\net45\OpenCvSharp.Extensions.dll 50 | True 51 | 52 | 53 | ..\packages\OpenCvSharp3-AnyCPU.3.1.0.20160622\lib\net45\OpenCvSharp.UserInterface.dll 54 | True 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 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 82 | 83 | 84 | 85 | 92 | -------------------------------------------------------------------------------- /dxcafe/ScoredMenu.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net.Http; 6 | using System.Net.Http.Headers; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace dxcafe 11 | { 12 | public class ScoredMenu 13 | { 14 | public ScoredMenu(double americano, double cafeRatte, double cafuChinno, double espresso, string topScoredMenu) 15 | { 16 | Americano = americano; 17 | CafeRatte = cafeRatte; 18 | CafuChino = cafuChinno; 19 | Espresso = espresso; 20 | TopScoredMenu = topScoredMenu; 21 | } 22 | 23 | public SortedDictionary GetSortedMenuList() 24 | { 25 | 26 | SortedDictionary sortedMenuList = new SortedDictionary(); 27 | sortedMenuList.Add("Americano", Americano); 28 | sortedMenuList.Add("Cafe Latte", CafeRatte); 29 | sortedMenuList.Add("Cappucino", CafuChino); 30 | sortedMenuList.Add("Espresso", Espresso); 31 | return sortedMenuList; 32 | } 33 | 34 | public static ScoredMenu Empty 35 | { 36 | get 37 | { 38 | return new ScoredMenu(0, 0, 0, 0, "unknown"); 39 | } 40 | } 41 | 42 | public double Americano { get; private set; } 43 | public double CafeRatte { get; private set; } 44 | public double CafuChino { get; private set; } 45 | public double Espresso { get; private set; } 46 | 47 | public string TopScoredMenu { get; private set; } 48 | } 49 | public enum Gender 50 | { 51 | Male, 52 | Femail 53 | } 54 | public static class MenuRecommender 55 | { 56 | public static async Task GetTopScoredMenu(string name, int age, Gender gender) 57 | { 58 | ScoredMenu menuScore = ScoredMenu.Empty; 59 | 60 | var scoreRequest = new 61 | { 62 | Inputs = new Dictionary>>() { 63 | { 64 | "input1", 65 | new List>(){new Dictionary(){ 66 | { 67 | "name", name 68 | }, 69 | { 70 | "age", age.ToString() 71 | }, 72 | { 73 | "date", "" 74 | }, 75 | { 76 | "gender", gender == Gender.Male ? "M" : "F" 77 | }, 78 | { 79 | "prodcts", "" 80 | }, 81 | } 82 | } 83 | }, 84 | }, 85 | GlobalParameters = new Dictionary() 86 | { 87 | } 88 | }; 89 | 90 | using (var client = new System.Net.Http.HttpClient()) 91 | { 92 | const string apiKey = "6EwIb5Om7prnsvyGpIXjsNnBzryfC5/tBcVEK/K+gxAtq9rF6Nt182fG9V6IW/Kn2iaxACcJGk0jmaDGh2cc7g=="; // Replace this with the API key for the web service 93 | client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", apiKey); 94 | client.BaseAddress = new Uri("https://japaneast.services.azureml.net/subscriptions/123d6582561440979417b9712cc9255b/services/866a9f6da9374e799256415921ff6656/execute?api-version=2.0&format=swagger"); 95 | // WARNING: The 'await' statement below can result in a deadlock 96 | // if you are calling this code from the UI thread of an ASP.Net application. 97 | // One way to address this would be to call ConfigureAwait(false) 98 | // so that the execution does not attempt to resume on the original context. 99 | // For instance, replace code such as: 100 | // result = await DoSomeTask() 101 | // with the following: 102 | // result = await DoSomeTask().ConfigureAwait(false) 103 | 104 | HttpResponseMessage response = await client.PostAsJsonAsync("", scoreRequest); 105 | 106 | if (response.IsSuccessStatusCode) 107 | { 108 | string result = await response.Content.ReadAsStringAsync(); 109 | JObject o = JObject.Parse(result); 110 | var obj = o["Results"]["output1"][0]; 111 | 112 | menuScore = new ScoredMenu( 113 | americano: obj["Scored Probabilities for Class \"Americano\""].Value(), 114 | cafeRatte: obj["Scored Probabilities for Class \"cafe ratte\""].Value(), 115 | cafuChinno: obj["Scored Probabilities for Class \"cafu chino\""].Value(), 116 | espresso: obj["Scored Probabilities for Class \"Espresso\""].Value(), 117 | topScoredMenu: obj["Scored Labels"].Value() 118 | ); 119 | } 120 | } 121 | 122 | return menuScore; 123 | } 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /ServiceHelpers/PhotoEvent.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using Microsoft.ProjectOxford.Emotion.Contract; 35 | using Newtonsoft.Json; 36 | using System; 37 | using System.Collections.Generic; 38 | using System.Linq; 39 | using System.Text; 40 | using System.Threading.Tasks; 41 | 42 | namespace ServiceHelpers 43 | { 44 | public class AgeGenderInfo 45 | { 46 | public double Age { get; set; } 47 | public string Gender { get; set; } 48 | } 49 | 50 | public class FaceInfo 51 | { 52 | public AgeGenderInfo AgeGenderInfo { get; set; } 53 | public Scores Emotion { get; set; } 54 | public string Name { get; set; } 55 | public string UniqueId { get; set; } 56 | } 57 | 58 | public class PhotoEvent 59 | { 60 | private static readonly JsonSerializerSettings jsonSettings = new JsonSerializerSettings() 61 | { 62 | // Stream Analytics will readjust all dates to UTC time so dont specify the timezone to preserve the localtime 63 | DateTimeZoneHandling = DateTimeZoneHandling.Unspecified 64 | }; 65 | 66 | public FaceInfo[] FaceInfo { get; set; } 67 | public DateTime LocalTime { get; set; } 68 | 69 | public string ToJson() 70 | { 71 | return JsonConvert.SerializeObject(this, jsonSettings); 72 | } 73 | 74 | public PhotoEvent(ImageAnalyzer capture) 75 | { 76 | LocalTime = DateTime.Now; 77 | 78 | List faceInfoList = new List(); 79 | 80 | if (capture.DetectedFaces != null) 81 | { 82 | foreach (var detectedFace in capture.DetectedFaces) 83 | { 84 | FaceInfo faceInfo = new FaceInfo(); 85 | 86 | // Check if we have age/gender for this face. 87 | if (detectedFace.FaceAttributes != null) 88 | { 89 | faceInfo.AgeGenderInfo = new AgeGenderInfo { Age = detectedFace.FaceAttributes.Age, Gender = detectedFace.FaceAttributes.Gender }; 90 | } 91 | 92 | // Check if we identified this face. If so send the name along. 93 | if (capture.IdentifiedPersons != null) 94 | { 95 | var matchingPerson = capture.IdentifiedPersons.FirstOrDefault(p => p.FaceId == detectedFace.FaceId); 96 | if (matchingPerson != null) 97 | { 98 | faceInfo.Name = matchingPerson.Person.Name; 99 | } 100 | } 101 | 102 | // Check if we have emotion for this face. If so send it along. 103 | if (capture.DetectedEmotion != null) 104 | { 105 | Emotion matchingEmotion = CoreUtil.FindFaceClosestToRegion(capture.DetectedEmotion, detectedFace.FaceRectangle); 106 | if (matchingEmotion != null) 107 | { 108 | faceInfo.Emotion = matchingEmotion.Scores; 109 | } 110 | } 111 | 112 | // Check if we have an unique Id for this face. If so send it along. 113 | if (capture.SimilarFaceMatches != null) 114 | { 115 | var matchingPerson = capture.SimilarFaceMatches.FirstOrDefault(p => p.Face.FaceId == detectedFace.FaceId); 116 | if (matchingPerson != null) 117 | { 118 | faceInfo.UniqueId = matchingPerson.SimilarPersistedFace.PersistedFaceId.ToString("N").Substring(0, 4); 119 | } 120 | } 121 | 122 | faceInfoList.Add(faceInfo); 123 | } 124 | } 125 | else if (capture.DetectedEmotion != null) 126 | { 127 | // If we are here we only have emotion. No age/gender or id. 128 | faceInfoList.AddRange(capture.DetectedEmotion.Select(emotion => new FaceInfo { Emotion = emotion.Scores })); 129 | } 130 | 131 | this.FaceInfo = faceInfoList.ToArray(); 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /dxcafe/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /ServiceHelpers/EmotionServiceHelper.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using Microsoft.ProjectOxford.Common; 35 | using Microsoft.ProjectOxford.Emotion; 36 | using Microsoft.ProjectOxford.Emotion.Contract; 37 | using System; 38 | using System.Collections.Generic; 39 | using System.IO; 40 | using System.Net.Http; 41 | using System.Threading.Tasks; 42 | 43 | namespace ServiceHelpers 44 | { 45 | public class EmotionData 46 | { 47 | public string EmotionName { get; set; } 48 | public float EmotionScore { get; set; } 49 | } 50 | 51 | public static class EmotionServiceHelper 52 | { 53 | public static int RetryCountOnQuotaLimitError = 6; 54 | public static int RetryDelayOnQuotaLimitError = 500; 55 | 56 | private static EmotionServiceClient emotionClient { get; set; } 57 | 58 | static EmotionServiceHelper() 59 | { 60 | InitializeEmotionService(); 61 | } 62 | 63 | public static Action Throttled; 64 | 65 | private static string apiKey; 66 | public static string ApiKey 67 | { 68 | get { return apiKey; } 69 | set 70 | { 71 | var changed = apiKey != value; 72 | apiKey = value; 73 | if (changed) 74 | { 75 | InitializeEmotionService(); 76 | } 77 | } 78 | } 79 | 80 | private static void InitializeEmotionService() 81 | { 82 | emotionClient = new EmotionServiceClient(apiKey); 83 | } 84 | 85 | private static async Task RunTaskWithAutoRetryOnQuotaLimitExceededError(Func> action) 86 | { 87 | int retriesLeft = FaceServiceHelper.RetryCountOnQuotaLimitError; 88 | int delay = FaceServiceHelper.RetryDelayOnQuotaLimitError; 89 | 90 | TResponse response = default(TResponse); 91 | 92 | while (true) 93 | { 94 | try 95 | { 96 | response = await action(); 97 | break; 98 | } 99 | catch (ClientException exception) when (exception.HttpStatus == (System.Net.HttpStatusCode)429 && retriesLeft > 0) 100 | { 101 | ErrorTrackingHelper.TrackException(exception, "Emotion API throttling error"); 102 | if (retriesLeft == 1 && Throttled != null) 103 | { 104 | Throttled(); 105 | } 106 | 107 | await Task.Delay(delay); 108 | retriesLeft--; 109 | delay *= 2; 110 | continue; 111 | } 112 | } 113 | 114 | return response; 115 | } 116 | 117 | private static async Task RunTaskWithAutoRetryOnQuotaLimitExceededError(Func action) 118 | { 119 | await RunTaskWithAutoRetryOnQuotaLimitExceededError(async () => { await action(); return null; }); 120 | } 121 | 122 | public static async Task RecognizeAsync(Stream imageStream) 123 | { 124 | return await RunTaskWithAutoRetryOnQuotaLimitExceededError(() => emotionClient.RecognizeAsync(imageStream)); 125 | } 126 | 127 | public static async Task RecognizeAsync(string url) 128 | { 129 | return await RunTaskWithAutoRetryOnQuotaLimitExceededError(() => emotionClient.RecognizeAsync(url)); 130 | } 131 | 132 | public static IEnumerable ScoresToEmotionData(Scores scores) 133 | { 134 | List result = new List(); 135 | result.Add(new EmotionData { EmotionName = "Anger", EmotionScore = scores.Anger }); 136 | result.Add(new EmotionData { EmotionName = "Contempt", EmotionScore = scores.Contempt }); 137 | result.Add(new EmotionData { EmotionName = "Disgust", EmotionScore = scores.Disgust }); 138 | result.Add(new EmotionData { EmotionName = "Fear", EmotionScore = scores.Fear }); 139 | result.Add(new EmotionData { EmotionName = "Happiness", EmotionScore = scores.Happiness }); 140 | result.Add(new EmotionData { EmotionName = "Neutral", EmotionScore = scores.Neutral }); 141 | result.Add(new EmotionData { EmotionName = "Sadness", EmotionScore = scores.Sadness }); 142 | result.Add(new EmotionData { EmotionName = "Surprise", EmotionScore = scores.Surprise }); 143 | 144 | return result; 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /ServiceHelpers/ServiceHelpers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 11.0 6 | Debug 7 | AnyCPU 8 | {5D9320AF-A9E4-48E3-89BC-9F7F0954B298} 9 | Library 10 | Properties 11 | ServiceHelpers 12 | ServiceHelpers 13 | en-US 14 | 512 15 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | Profile7 17 | v4.5 18 | SAK 19 | SAK 20 | SAK 21 | SAK 22 | 23 | 24 | 25 | 26 | true 27 | full 28 | false 29 | bin\Debug\ 30 | DEBUG;TRACE 31 | prompt 32 | 4 33 | 34 | 35 | pdbonly 36 | true 37 | bin\Release\ 38 | TRACE 39 | prompt 40 | 4 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | ..\packages\Microsoft.ProjectOxford.Common.1.0.308\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Common.dll 57 | True 58 | 59 | 60 | ..\packages\Microsoft.ProjectOxford.Emotion.1.0.326\lib\portable45-net45+win8+wp8+wpa81\Microsoft.ProjectOxford.Emotion.dll 61 | True 62 | 63 | 64 | ..\packages\Microsoft.ProjectOxford.Face.1.1.0\lib\portable-net45+wp80+win8+wpa81+aspnetcore50\Microsoft.ProjectOxford.Face.dll 65 | True 66 | 67 | 68 | ..\packages\Newtonsoft.Json.8.0.2\lib\portable-net40+sl5+wp80+win8+wpa81\Newtonsoft.Json.dll 69 | True 70 | 71 | 72 | ..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net45+win8\System.Net.Http.Extensions.dll 73 | True 74 | 75 | 76 | ..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net45+win8\System.Net.Http.Primitives.dll 77 | True 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 89 | 90 | 91 | 92 | 99 | -------------------------------------------------------------------------------- /dxcafe/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 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 | 59 | 62 | 65 | 68 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 81 | 82 | 83 | 84 | 85 | 86 | 125 | 126 | -------------------------------------------------------------------------------- /ServiceHelpers/BingSearchHelper.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using Newtonsoft.Json.Linq; 35 | using System; 36 | using System.Collections.Generic; 37 | using System.Linq; 38 | using System.Net; 39 | using System.Net.Http; 40 | using System.Net.Http.Headers; 41 | using System.Text; 42 | using System.Threading.Tasks; 43 | 44 | namespace ServiceHelpers 45 | { 46 | public class BingSearchHelper 47 | { 48 | private static string ImageSearchEndPoint = "https://api.cognitive.microsoft.com/bing/v5.0/images/search"; 49 | private static string AutoSuggestionEndPoint = "https://api.cognitive.microsoft.com/bing/v5.0/suggestions"; 50 | private static string NewsSearchEndPoint = "https://api.cognitive.microsoft.com/bing/v5.0/news/search"; 51 | 52 | private static HttpClient autoSuggestionClient { get; set; } 53 | private static HttpClient searchClient { get; set; } 54 | 55 | private static string autoSuggestionApiKey; 56 | public static string AutoSuggestionApiKey 57 | { 58 | get { return autoSuggestionApiKey; } 59 | set 60 | { 61 | var changed = autoSuggestionApiKey != value; 62 | autoSuggestionApiKey = value; 63 | if (changed) 64 | { 65 | InitializeBingClients(); 66 | } 67 | } 68 | } 69 | 70 | private static string searchApiKey; 71 | public static string SearchApiKey 72 | { 73 | get { return searchApiKey; } 74 | set 75 | { 76 | var changed = searchApiKey != value; 77 | searchApiKey = value; 78 | if (changed) 79 | { 80 | InitializeBingClients(); 81 | } 82 | } 83 | } 84 | 85 | private static void InitializeBingClients() 86 | { 87 | autoSuggestionClient = new HttpClient(); 88 | autoSuggestionClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", AutoSuggestionApiKey); 89 | 90 | searchClient = new HttpClient(); 91 | searchClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", SearchApiKey); 92 | } 93 | 94 | public static async Task> GetImageSearchResults(string query, string imageContent = "Face", int count = 20, int offset = 0) 95 | { 96 | List urls = new List(); 97 | 98 | var result = await searchClient.GetAsync(string.Format("{0}?q={1}&safeSearch=Strict&imageType=Photo&color=ColorOnly&count={2}&offset={3}{4}", ImageSearchEndPoint, WebUtility.UrlEncode(query), count, offset, string.IsNullOrEmpty(imageContent) ? "" : "&imageContent=" + imageContent)); 99 | result.EnsureSuccessStatusCode(); 100 | var json = await result.Content.ReadAsStringAsync(); 101 | dynamic data = JObject.Parse(json); 102 | if (data.value != null && data.value.Count > 0) 103 | { 104 | for (int i = 0; i < data.value.Count; i++) 105 | { 106 | urls.Add(data.value[i].contentUrl.Value); 107 | } 108 | } 109 | 110 | return urls; 111 | } 112 | 113 | public static async Task> GetAutoSuggestResults(string query, string market = "en-US") 114 | { 115 | List suggestions = new List(); 116 | 117 | var result = await autoSuggestionClient.GetAsync(string.Format("{0}/?q={1}&mkt={2}", AutoSuggestionEndPoint, WebUtility.UrlEncode(query), market)); 118 | result.EnsureSuccessStatusCode(); 119 | var json = await result.Content.ReadAsStringAsync(); 120 | dynamic data = JObject.Parse(json); 121 | if (data.suggestionGroups != null && data.suggestionGroups.Count > 0 && 122 | data.suggestionGroups[0].searchSuggestions != null) 123 | { 124 | for (int i = 0; i < data.suggestionGroups[0].searchSuggestions.Count; i++) 125 | { 126 | suggestions.Add(data.suggestionGroups[0].searchSuggestions[i].displayText.Value); 127 | } 128 | } 129 | 130 | return suggestions; 131 | } 132 | 133 | 134 | public static async Task> GetNewsSearchResults(string query, int count = 20, int offset = 0, string market = "en-US") 135 | { 136 | List articles = new List(); 137 | 138 | var result = await searchClient.GetAsync(string.Format("{0}/?q={1}&count={2}&offset={3}&mkt={4}", NewsSearchEndPoint, WebUtility.UrlEncode(query), count, offset, market)); 139 | result.EnsureSuccessStatusCode(); 140 | var json = await result.Content.ReadAsStringAsync(); 141 | dynamic data = JObject.Parse(json); 142 | 143 | if (data.value != null && data.value.Count > 0) 144 | { 145 | for (int i = 0; i < data.value.Count; i++) 146 | { 147 | articles.Add(new NewsArticle 148 | { 149 | Title = data.value[i].name, 150 | Url = data.value[i].url, 151 | Description = data.value[i].description, 152 | ThumbnailUrl = data.value[i].image?.thumbnail?.contentUrl, 153 | Provider = data.value[i].provider?[0].name 154 | }); 155 | } 156 | } 157 | return articles; 158 | } 159 | 160 | } 161 | 162 | public class NewsArticle 163 | { 164 | public string Title { get; set; } 165 | public string Description { get; set; } 166 | public string Url { get; set; } 167 | public string ThumbnailUrl { get; set; } 168 | public string Provider { get; set; } 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /ServiceHelpers/TextAnalyticsHelper.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using Newtonsoft.Json; 35 | using System; 36 | using System.Collections.Generic; 37 | using System.Linq; 38 | using System.Text; 39 | using System.Threading.Tasks; 40 | using System.Net.Http; 41 | using System.Net.Http.Headers; 42 | using System.Net; 43 | using Newtonsoft.Json.Linq; 44 | 45 | namespace ServiceHelpers 46 | { 47 | public class TextAnalyticsHelper 48 | { 49 | private const string ServiceBaseUri = "https://westus.api.cognitive.microsoft.com/"; 50 | 51 | private static HttpClient httpClient { get; set; } 52 | 53 | private static string apiKey; 54 | 55 | public static string ApiKey 56 | { 57 | get { return apiKey; } 58 | set 59 | { 60 | var changed = apiKey != value; 61 | apiKey = value; 62 | if (changed) 63 | { 64 | InitializeTextAnalyticsClient(); 65 | } 66 | } 67 | } 68 | 69 | private static void InitializeTextAnalyticsClient() 70 | { 71 | httpClient = new HttpClient(); 72 | httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", ApiKey); 73 | httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 74 | httpClient.BaseAddress = new Uri(ServiceBaseUri); 75 | } 76 | 77 | public static async Task GetTextSentimentAsync(string[] input, string language = "en") 78 | { 79 | SentimentResult sentimentResult = new SentimentResult() { Scores = new double[] { 0.5 } }; 80 | 81 | if (input != null) 82 | { 83 | // Request body. 84 | string requestString = "{\"documents\":["; 85 | for (int i = 0; i < input.Length; i++) 86 | { 87 | requestString += string.Format("{{\"id\":\"{0}\",\"text\":\"{1}\", \"language\":\"{2}\"}}", i, input[i].Replace("\"", "'"), language); 88 | if (i != input.Length - 1) 89 | { 90 | requestString += ","; 91 | } 92 | } 93 | 94 | requestString += "]}"; 95 | 96 | byte[] byteData = Encoding.UTF8.GetBytes(requestString); 97 | 98 | // get sentiment 99 | string uri = "text/analytics/v2.0/sentiment"; 100 | var response = await CallEndpoint(httpClient, uri, byteData); 101 | string content = await response.Content.ReadAsStringAsync(); 102 | if (!response.IsSuccessStatusCode) 103 | { 104 | throw new Exception("Text Analytics failed. " + content); 105 | } 106 | dynamic data = JObject.Parse(content); 107 | Dictionary scores = new Dictionary(); 108 | if (data.documents != null) 109 | { 110 | for (int i = 0; i < data.documents.Count; i++) 111 | { 112 | scores[(int)data.documents[i].id] = data.documents[i].score; 113 | } 114 | } 115 | 116 | if (data.errors != null) 117 | { 118 | for (int i = 0; i < data.errors.Count; i++) 119 | { 120 | scores[(int)data.errors[i].id] = 0.5; 121 | } 122 | } 123 | 124 | sentimentResult = new SentimentResult { Scores = scores.OrderBy(s => s.Key).Select(s => s.Value) }; 125 | } 126 | 127 | return sentimentResult; 128 | } 129 | 130 | public static async Task GetKeyPhrasesAsync(string[] input, string language = "en") 131 | { 132 | KeyPhrasesResult result = new KeyPhrasesResult() { KeyPhrases = Enumerable.Empty>() }; 133 | 134 | if (input != null) 135 | { 136 | // Request body. 137 | string requestString = "{\"documents\":["; 138 | for (int i = 0; i < input.Length; i++) 139 | { 140 | requestString += string.Format("{{\"id\":\"{0}\",\"text\":\"{1}\", \"language\":\"{2}\"}}", i, input[i].Replace("\"", "'"), language); 141 | if (i != input.Length - 1) 142 | { 143 | requestString += ","; 144 | } 145 | } 146 | 147 | requestString += "]}"; 148 | 149 | byte[] byteData = Encoding.UTF8.GetBytes(requestString); 150 | 151 | // get sentiment 152 | string uri = "text/analytics/v2.0/keyPhrases"; 153 | var response = await CallEndpoint(httpClient, uri, byteData); 154 | string content = await response.Content.ReadAsStringAsync(); 155 | if (!response.IsSuccessStatusCode) 156 | { 157 | throw new Exception("Text Analytics failed. " + content); 158 | } 159 | dynamic data = JObject.Parse(content); 160 | Dictionary> phrasesDictionary = new Dictionary>(); 161 | if (data.documents != null) 162 | { 163 | for (int i = 0; i < data.documents.Count; i++) 164 | { 165 | List phrases = new List(); 166 | 167 | for (int j = 0; j < data.documents[i].keyPhrases.Count; j++) 168 | { 169 | phrases.Add((string)data.documents[i].keyPhrases[j]); 170 | } 171 | phrasesDictionary[i] = phrases; 172 | } 173 | } 174 | 175 | if (data.errors != null) 176 | { 177 | for (int i = 0; i < data.errors.Count; i++) 178 | { 179 | phrasesDictionary[i] = Enumerable.Empty(); 180 | } 181 | } 182 | 183 | result.KeyPhrases = phrasesDictionary.OrderBy(e => e.Key).Select(e => e.Value); 184 | } 185 | 186 | return result; 187 | } 188 | 189 | static async Task CallEndpoint(HttpClient client, string uri, byte[] byteData) 190 | { 191 | using (var content = new ByteArrayContent(byteData)) 192 | { 193 | content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); 194 | return await client.PostAsync(uri, content); 195 | } 196 | } 197 | } 198 | 199 | /// Class to hold result of Sentiment call 200 | /// 201 | public class SentimentResult 202 | { 203 | public IEnumerable Scores { get; set; } 204 | } 205 | 206 | public class KeyPhrasesResult 207 | { 208 | public IEnumerable> KeyPhrases { get; set; } 209 | } 210 | 211 | } 212 | -------------------------------------------------------------------------------- /ServiceHelpers/FaceListManager.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services: http://www.microsoft.com/cognitive 6 | // 7 | // Microsoft Cognitive Services Github: 8 | // https://github.com/Microsoft/Cognitive 9 | // 10 | // Copyright (c) Microsoft Corporation 11 | // All rights reserved. 12 | // 13 | // MIT License: 14 | // Permission is hereby granted, free of charge, to any person obtaining 15 | // a copy of this software and associated documentation files (the 16 | // "Software"), to deal in the Software without restriction, including 17 | // without limitation the rights to use, copy, modify, merge, publish, 18 | // distribute, sublicense, and/or sell copies of the Software, and to 19 | // permit persons to whom the Software is furnished to do so, subject to 20 | // the following conditions: 21 | // 22 | // The above copyright notice and this permission notice shall be 23 | // included in all copies or substantial portions of the Software. 24 | // 25 | // THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, 26 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 27 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 28 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 29 | // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 30 | // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 31 | // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 32 | // 33 | 34 | using Microsoft.ProjectOxford.Face; 35 | using Microsoft.ProjectOxford.Face.Contract; 36 | using System; 37 | using System.Collections.Generic; 38 | using System.IO; 39 | using System.Linq; 40 | using System.Threading.Tasks; 41 | 42 | namespace ServiceHelpers 43 | { 44 | internal class FaceListInfo 45 | { 46 | public string FaceListId { get; set; } 47 | public DateTime LastMatchTimestamp { get; set; } 48 | public bool IsFull { get; set; } 49 | } 50 | 51 | public class FaceListManager 52 | { 53 | private static Dictionary faceLists; 54 | 55 | public static string FaceListsUserDataFilter { get; set; } 56 | 57 | private FaceListManager() { } 58 | 59 | public static async Task ResetFaceLists() 60 | { 61 | faceLists = new Dictionary(); 62 | 63 | try 64 | { 65 | IEnumerable metadata = await FaceServiceHelper.GetFaceListsAsync(FaceListsUserDataFilter); 66 | foreach (var item in metadata) 67 | { 68 | await FaceServiceHelper.DeleteFaceListAsync(item.FaceListId); 69 | } 70 | } 71 | catch (Exception e) 72 | { 73 | ErrorTrackingHelper.TrackException(e, "Error resetting face lists"); 74 | } 75 | } 76 | 77 | public static async Task Initialize() 78 | { 79 | faceLists = new Dictionary(); 80 | 81 | try 82 | { 83 | IEnumerable metadata = await FaceServiceHelper.GetFaceListsAsync(FaceListsUserDataFilter); 84 | foreach (var item in metadata) 85 | { 86 | faceLists.Add(item.FaceListId, new FaceListInfo { FaceListId = item.FaceListId, LastMatchTimestamp = DateTime.Now }); 87 | } 88 | } 89 | catch (Exception e) 90 | { 91 | ErrorTrackingHelper.TrackException(e, "Face API GetFaceListsAsync error"); 92 | } 93 | } 94 | 95 | public static async Task FindSimilarPersistedFaceAsync(Stream imageStream, Guid faceId, FaceRectangle faceRectangle) 96 | { 97 | if (faceLists == null) 98 | { 99 | await Initialize(); 100 | } 101 | 102 | Tuple bestMatch = null; 103 | 104 | bool foundMatch = false; 105 | foreach (var faceListId in faceLists.Keys) 106 | { 107 | try 108 | { 109 | SimilarPersistedFace similarFace = (await FaceServiceHelper.FindSimilarAsync(faceId, faceListId))?.FirstOrDefault(); 110 | if (similarFace == null) 111 | { 112 | continue; 113 | } 114 | 115 | foundMatch = true; 116 | 117 | if (bestMatch != null) 118 | { 119 | // We already found a match for this face in another list. Replace the previous one if the new confidence is higher. 120 | if (bestMatch.Item1.Confidence < similarFace.Confidence) 121 | { 122 | bestMatch = new Tuple(similarFace, faceListId); 123 | } 124 | } 125 | else 126 | { 127 | bestMatch = new Tuple(similarFace, faceListId); 128 | } 129 | } 130 | catch (Exception e) 131 | { 132 | // Catch errors with individual face lists so we can continue looping through all lists. Maybe an answer will come from 133 | // another one. 134 | ErrorTrackingHelper.TrackException(e, "Face API FindSimilarAsync error"); 135 | } 136 | } 137 | 138 | if (!foundMatch) 139 | { 140 | // If we are here we didnt' find a match, so let's add the face to the first FaceList that we can add it to. We 141 | // might create a new list if none exist, and if all lists are full we will delete the oldest face list (based on when we 142 | // last matched anything on it) so that we can add the new one. 143 | 144 | if (!faceLists.Any()) 145 | { 146 | // We don't have any FaceLists yet. Create one 147 | string newFaceListId = Guid.NewGuid().ToString(); 148 | await FaceServiceHelper.CreateFaceListAsync(newFaceListId, "ManagedFaceList", FaceListsUserDataFilter); 149 | 150 | faceLists.Add(newFaceListId, new FaceListInfo { FaceListId = newFaceListId, LastMatchTimestamp = DateTime.Now }); 151 | } 152 | 153 | AddPersistedFaceResult addResult = null; 154 | bool failedToAddToNonFullList = false; 155 | foreach (var faceList in faceLists) 156 | { 157 | if (faceList.Value.IsFull) 158 | { 159 | continue; 160 | } 161 | 162 | try 163 | { 164 | addResult = await FaceServiceHelper.AddFaceToFaceListAsync(faceList.Key, imageStream, faceRectangle); 165 | break; 166 | } 167 | catch (Exception ex) 168 | { 169 | if (ex is FaceAPIException && ((FaceAPIException)ex).ErrorCode == "403") 170 | { 171 | // FaceList is full. Continue so we can try again with the next FaceList 172 | faceList.Value.IsFull = true; 173 | continue; 174 | } 175 | else 176 | { 177 | failedToAddToNonFullList = true; 178 | break; 179 | } 180 | } 181 | } 182 | 183 | if (addResult == null && !failedToAddToNonFullList) 184 | { 185 | // We were not able to add the face to an existing list because they were all full. 186 | 187 | // If possible, let's create a new list now and add the new face to it. If we can't (e.g. we already maxed out on list count), 188 | // let's delete an old list, create a new one and add the new face to it. 189 | 190 | if (faceLists.Count == 64) 191 | { 192 | // delete oldest face list 193 | var oldestFaceList = faceLists.OrderBy(fl => fl.Value.LastMatchTimestamp).FirstOrDefault(); 194 | faceLists.Remove(oldestFaceList.Key); 195 | await FaceServiceHelper.DeleteFaceListAsync(oldestFaceList.Key); 196 | } 197 | 198 | // create new list 199 | string newFaceListId = Guid.NewGuid().ToString(); 200 | await FaceServiceHelper.CreateFaceListAsync(newFaceListId, "ManagedFaceList", FaceListsUserDataFilter); 201 | faceLists.Add(newFaceListId, new FaceListInfo { FaceListId = newFaceListId, LastMatchTimestamp = DateTime.Now }); 202 | 203 | // Add face to new list 204 | addResult = await FaceServiceHelper.AddFaceToFaceListAsync(newFaceListId, imageStream, faceRectangle); 205 | } 206 | 207 | if (addResult != null) 208 | { 209 | bestMatch = new Tuple(new SimilarPersistedFace { Confidence = 1, PersistedFaceId = addResult.PersistedFaceId }, null); 210 | } 211 | } 212 | 213 | return bestMatch?.Item1; 214 | } 215 | } 216 | } 217 | -------------------------------------------------------------------------------- /dxcafe/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.ProjectOxford.Face; 2 | using OpenCvSharp; 3 | using ServiceHelpers; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows; 10 | using System.Windows.Controls; 11 | using System.Windows.Data; 12 | using System.Windows.Documents; 13 | using System.Windows.Input; 14 | using System.Windows.Media; 15 | using System.Windows.Media.Imaging; 16 | using System.Windows.Navigation; 17 | using System.Windows.Shapes; 18 | using VideoFrameAnalyzer; 19 | using OpenCvSharp.Extensions; 20 | using System.Diagnostics; 21 | using Microsoft.ProjectOxford.Face.Contract; 22 | 23 | namespace dxcafe 24 | { 25 | /// 26 | /// Interaction logic for MainWindow.xaml 27 | /// 28 | public partial class MainWindow : System.Windows.Window 29 | { 30 | public const string faceKey = "7d63e81223db4b9ab41f064a1a8a609f"; 31 | private FaceServiceClient faceClient = new FaceServiceClient(faceKey); 32 | private readonly FrameGrabber grabber = new FrameGrabber(); 33 | private readonly CascadeClassifier localFaceDetector = new CascadeClassifier(); 34 | 35 | private static readonly ImageEncodingParam[] jpegParams = 36 | { 37 | new ImageEncodingParam(ImwriteFlags.JpegQuality, 60) 38 | }; 39 | 40 | private bool _fuseClientRemoteResults; 41 | private LiveCameraResult _latestResultsToDisplay = null; 42 | 43 | 44 | public MainWindow() 45 | { 46 | InitializeComponent(); 47 | grabber.AnalysisFunction = FacesAnalysisFunction; 48 | grabber.NewFrameProvided += Grabber_NewFrameProvided; 49 | grabber.NewResultAvailable += Grabber_NewResultAvailable; 50 | grabber.TriggerAnalysisOnInterval(TimeSpan.FromMilliseconds(5000)); 51 | 52 | localFaceDetector.Load("Data/haarcascade_frontalface_alt2.xml"); 53 | 54 | } 55 | 56 | // recognited face 57 | private void Grabber_NewResultAvailable(object sender, FrameGrabber.NewResultEventArgs e) 58 | { 59 | string age = string.Empty; 60 | string gender = string.Empty; 61 | string id = string.Empty; 62 | 63 | age = e.Analysis.Faces.FirstOrDefault()?.FaceAttributes.Age.ToString(); 64 | gender = e.Analysis.Faces.FirstOrDefault()?.FaceAttributes.Gender.ToString(); 65 | id = e.Analysis.Faces.FirstOrDefault()?.FaceId.ToString(); 66 | 67 | Dispatcher.BeginInvoke((Action)(() => 68 | { 69 | TextBox.Text += $"Face Detected, Age={age}, Gender={gender}, id={id}\n"; 70 | })); 71 | } 72 | 73 | // 74 | private async Task FacesAnalysisFunction(VideoFrame frame) 75 | { 76 | Face[] faces = null; 77 | 78 | try 79 | { 80 | // Encode image. 81 | var jpg = frame.Image.ToMemoryStream(".jpg", jpegParams); 82 | // Submit image to API. 83 | var attrs = new List { FaceAttributeType.Age, 84 | FaceAttributeType.Gender, FaceAttributeType.HeadPose }; 85 | faces = await faceClient.DetectAsync(jpg, returnFaceAttributes: attrs); 86 | 87 | //"personGroupId": "36fef99e-f1a6-42e2-843e-b9fcee2b56a0", 88 | //"name": "ISV", 89 | //"userData": "a61934e8-d8ec-477c-b6a5-a715ed314bd6" 90 | //"personid" {50eabdcb-4dd9-4101-bf7c-40f0c7863b24}" 91 | 92 | 93 | if (faces != null & faces.Length > 0) 94 | { 95 | string personGroupId = "36fef99e-f1a6-42e2-843e-b9fcee2b56a0"; 96 | var persons = await faceClient.IdentifyAsync(personGroupId, new Guid[] { faces[0].FaceId }); 97 | 98 | if (persons != null && persons.Length > 0) 99 | { 100 | if (persons[0].Candidates != null && persons[0].Candidates.Length > 0) 101 | { 102 | Person person = await faceClient.GetPersonAsync(personGroupId, persons[0].Candidates[0].PersonId); 103 | await Dispatcher.BeginInvoke((Action)(() => 104 | { 105 | TextBox.Text += $"Person Detected, Name={person.Name}\n"; 106 | UpdatePerson(person.Name, (int)faces[0].FaceAttributes.Age, faces[0].FaceAttributes.Gender ); 107 | })); 108 | } 109 | } 110 | } 111 | } 112 | catch (Microsoft.ProjectOxford.Face.FaceAPIException ex) 113 | { 114 | Debug.WriteLine(ex.ToString()); 115 | } 116 | 117 | return new LiveCameraResult { Faces = faces }; 118 | } 119 | 120 | private async void UpdatePerson(string name, int age, string gender) 121 | { 122 | Team.Text = "ISV"; 123 | Name.Text = name; 124 | switch (name) 125 | { 126 | case "Myung Shin Kim": 127 | picture.Source = new BitmapImage(new Uri(@"/images/m.jpg", UriKind.Relative)); 128 | Gender.Text = "Male"; 129 | Age.Text = "45"; 130 | break; 131 | case "Bong Joo Kim": 132 | picture.Source = new BitmapImage(new Uri(@"/images/b.jpg", UriKind.Relative)); 133 | Gender.Text = "Female"; 134 | Age.Text = "20"; 135 | break; 136 | 137 | case "Yi Hyun Kim": 138 | picture.Source = new BitmapImage(new Uri(@"/images/y.jpg", UriKind.Relative)); 139 | Gender.Text = "Female"; 140 | Age.Text = "25"; 141 | break; 142 | } 143 | 144 | ScoredMenu sm = await MenuRecommender.GetTopScoredMenu(name, age, gender == "male" ? dxcafe.Gender.Male : dxcafe.Gender.Femail); 145 | SortedDictionary list = sm.GetSortedMenuList(); 146 | 147 | SortedList> sortedList = new SortedList>(); 148 | foreach(var each in list) 149 | { 150 | sortedList.Add(each.Value, each); 151 | } 152 | 153 | /* 154 | * 155 | 156 | 159 | 162 | 165 |