├── .gitattributes ├── .gitignore ├── LiveCam ├── LiveCam.Droid │ ├── Assets │ │ └── AboutAssets.txt │ ├── CustomControls │ │ ├── CameraSourcePreview.cs │ │ └── GraphicOverlay.cs │ ├── FaceGraphic.cs │ ├── GettingStarted.Xamarin │ ├── LiveCam.Droid.csproj │ ├── MainActivity.cs │ ├── Properties │ │ ├── AndroidManifest.xml │ │ └── AssemblyInfo.cs │ ├── Resources │ │ ├── AboutResources.txt │ │ ├── Resource.Designer.cs │ │ ├── drawable │ │ │ └── Icon.png │ │ ├── layout │ │ │ └── Main.axml │ │ └── values │ │ │ └── Strings.xml │ ├── app.config │ └── packages.config ├── LiveCam.Shared │ ├── LiveCam.Shared.projitems │ ├── LiveCam.Shared.shproj │ └── LiveCamHelper.cs ├── LiveCam.sln ├── LiveCam │ ├── AppDelegate.cs │ ├── Entitlements.plist │ ├── GettingStarted.Xamarin │ ├── Info.plist │ ├── LiveCam.iOS.csproj │ ├── Main.cs │ ├── Main.storyboard │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Resources │ │ ├── LaunchScreen.xib │ │ └── square.png │ ├── UIExtensions.cs │ ├── ViewController.cs │ ├── ViewController.designer.cs │ └── app.config ├── Microsoft.ProjectOxford.Face │ ├── Contract │ │ ├── AddPersistedFaceResult.cs │ │ ├── Candidate.cs │ │ ├── ClientError.cs │ │ ├── CreatePersonResult.cs │ │ ├── Face.cs │ │ ├── FaceAttributes.cs │ │ ├── FaceLandmarks.cs │ │ ├── FaceList.cs │ │ ├── FaceListMetadata.cs │ │ ├── FaceMetadata.cs │ │ ├── FaceRectangle.cs │ │ ├── FacialHair.cs │ │ ├── FeatureCoordinate.cs │ │ ├── GlassesTypes.cs │ │ ├── GroupResult.cs │ │ ├── HeadPose.cs │ │ ├── IdentifyResult.cs │ │ ├── Person.cs │ │ ├── PersonFace.cs │ │ ├── PersonGroup.cs │ │ ├── SimilarFace.cs │ │ ├── SimilarPersistedFace.cs │ │ ├── TrainingStatus.cs │ │ └── VerifyResult.cs │ ├── FaceAPIException.cs │ ├── FaceClientSDK.nuspec │ ├── FaceServiceClient.cs │ ├── IFaceServiceClient.cs │ ├── Microsoft.ProjectOxford.Face.csproj │ ├── Microsoft.ProjectOxford.Face.sln │ ├── Properties │ │ └── AssemblyInfo.cs │ └── packages.config └── ServiceHelpers │ ├── BingSearchHelper.cs │ ├── CoreUtil.cs │ ├── EmotionServiceHelper.cs │ ├── ErrorTrackingHelper.cs │ ├── FaceListManager.cs │ ├── FaceServiceHelper.cs │ ├── ImageAnalyzer.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── ServiceHelpers.csproj │ ├── TextAnalyticsHelper.cs │ ├── VisionServiceHelper.cs │ ├── app.config │ └── packages.config └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.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 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 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 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | 254 | # ========================= 255 | # Operating System Files 256 | # ========================= 257 | 258 | # OSX 259 | # ========================= 260 | 261 | .DS_Store 262 | .AppleDouble 263 | .LSOverride 264 | 265 | # Thumbnails 266 | ._* 267 | 268 | # Files that might appear in the root of a volume 269 | .DocumentRevisions-V100 270 | .fseventsd 271 | .Spotlight-V100 272 | .TemporaryItems 273 | .Trashes 274 | .VolumeIcon.icns 275 | 276 | # Directories potentially created on remote AFP share 277 | .AppleDB 278 | .AppleDesktop 279 | Network Trash Folder 280 | Temporary Items 281 | .apdisk 282 | 283 | # Windows 284 | # ========================= 285 | 286 | # Windows image file caches 287 | Thumbs.db 288 | ehthumbs.db 289 | 290 | # Folder config file 291 | Desktop.ini 292 | 293 | # Recycle Bin used on file shares 294 | $RECYCLE.BIN/ 295 | 296 | # Windows Installer files 297 | *.cab 298 | *.msi 299 | *.msm 300 | *.msp 301 | 302 | # Windows shortcuts 303 | *.lnk 304 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/Assets/AboutAssets.txt: -------------------------------------------------------------------------------- 1 | Any raw assets you want to be deployed with your application can be placed in 2 | this directory (and child directories) and given a Build Action of "AndroidAsset". 3 | 4 | These files will be deployed with you package and will be accessible using Android's 5 | AssetManager, like this: 6 | 7 | public class ReadAsset : Activity 8 | { 9 | protected override void OnCreate (Bundle bundle) 10 | { 11 | base.OnCreate (bundle); 12 | 13 | InputStream input = Assets.Open ("my_asset.txt"); 14 | } 15 | } 16 | 17 | Additionally, some Android functions will automatically load asset files: 18 | 19 | Typeface tf = Typeface.CreateFromAsset (Context.Assets, "fonts/samplefont.ttf"); -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/CustomControls/CameraSourcePreview.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Ported to C# from https://github.com/googlesamples/android-vision/tree/master/visionSamples/FaceTracker 3 | * Ported by Nish Anil (Nish@microsoft.com) 4 | * Copyright (C) The Android Open Source Project 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | using System; 20 | using System.Collections.Generic; 21 | using System.Linq; 22 | using System.Text; 23 | 24 | using Android.App; 25 | using Android.Content; 26 | using Android.OS; 27 | using Android.Runtime; 28 | using Android.Views; 29 | using Android.Widget; 30 | using Android.Util; 31 | using Android.Gms.Vision; 32 | using Android.Graphics; 33 | using Android.Content.Res; 34 | using Android.Hardware; 35 | 36 | namespace LiveCam.Droid 37 | { 38 | 39 | 40 | public sealed class CameraSourcePreview : ViewGroup, ISurfaceHolderCallback 41 | { 42 | private static readonly String TAG = "CameraSourcePreview"; 43 | 44 | private Context mContext; 45 | private SurfaceView mSurfaceView; 46 | private bool mStartRequested; 47 | private bool mSurfaceAvailable; 48 | private CameraSource mCameraSource; 49 | 50 | private GraphicOverlay mOverlay; 51 | 52 | 53 | public CameraSourcePreview(Context context, IAttributeSet attrs) : base(context, attrs) 54 | { 55 | mContext = context; 56 | mStartRequested = false; 57 | mSurfaceAvailable = false; 58 | 59 | mSurfaceView = new SurfaceView(context); 60 | mSurfaceView.Holder.AddCallback(this); 61 | 62 | AddView(mSurfaceView); 63 | } 64 | 65 | 66 | public void Start(CameraSource cameraSource) 67 | { 68 | if (cameraSource == null) 69 | { 70 | Stop(); 71 | } 72 | 73 | mCameraSource = cameraSource; 74 | 75 | if (mCameraSource != null) 76 | { 77 | mStartRequested = true; 78 | StartIfReady(); 79 | } 80 | } 81 | 82 | public void Start(CameraSource cameraSource, GraphicOverlay overlay) 83 | { 84 | mOverlay = overlay; 85 | Start(cameraSource); 86 | } 87 | 88 | public void Stop() 89 | { 90 | if (mCameraSource != null) 91 | { 92 | mCameraSource.Stop(); 93 | } 94 | } 95 | 96 | public void Release() 97 | { 98 | if (mCameraSource != null) 99 | { 100 | mCameraSource.Release(); 101 | mCameraSource = null; 102 | } 103 | } 104 | private void StartIfReady() 105 | { 106 | if (mStartRequested && mSurfaceAvailable) 107 | { 108 | mCameraSource.Start(mSurfaceView.Holder); 109 | if (mOverlay != null) 110 | { 111 | var size = mCameraSource.PreviewSize; 112 | var min = Math.Min(size.Width, size.Height); 113 | var max = Math.Max(size.Width, size.Height); 114 | if (IsPortraitMode()) 115 | { 116 | // Swap width and height sizes when in portrait, since it will be rotated by 117 | // 90 degrees 118 | mOverlay.SetCameraInfo(min, max, mCameraSource.CameraFacing); 119 | } 120 | else 121 | { 122 | mOverlay.SetCameraInfo(max, min, mCameraSource.CameraFacing); 123 | } 124 | mOverlay.Clear(); 125 | } 126 | mStartRequested = false; 127 | } 128 | } 129 | 130 | private bool IsPortraitMode() 131 | { 132 | var orientation = mContext.Resources.Configuration.Orientation; 133 | if (orientation == Android.Content.Res.Orientation.Landscape) 134 | { 135 | return false; 136 | } 137 | if (orientation == Android.Content.Res.Orientation.Portrait) 138 | { 139 | return true; 140 | } 141 | 142 | Log.Debug(TAG, "isPortraitMode returning false by default"); 143 | return false; 144 | } 145 | 146 | 147 | 148 | public void SurfaceChanged(ISurfaceHolder holder, [GeneratedEnum] Format format, int width, int height) 149 | { 150 | 151 | } 152 | 153 | public void SurfaceCreated(ISurfaceHolder holder) 154 | { 155 | mSurfaceAvailable = true; 156 | 157 | 158 | try 159 | { 160 | StartIfReady(); 161 | } 162 | catch (Exception e) 163 | { 164 | Log.Error(TAG, "Could not start camera source.", e); 165 | } 166 | } 167 | 168 | public void SurfaceDestroyed(ISurfaceHolder holder) 169 | { 170 | mSurfaceAvailable = false; 171 | } 172 | 173 | protected override void OnLayout(bool changed, int l, int t, int r, int b) 174 | { 175 | int width = 320; 176 | int height = 240; 177 | if (mCameraSource != null) 178 | { 179 | var size = mCameraSource.PreviewSize; 180 | if (size != null) 181 | { 182 | width = size.Width; 183 | height = size.Height; 184 | } 185 | } 186 | 187 | // Swap width and height sizes when in portrait, since it will be rotated 90 degrees 188 | if (IsPortraitMode()) 189 | { 190 | int tmp = width; 191 | width = height; 192 | height = tmp; 193 | } 194 | 195 | int layoutWidth = r - l; 196 | int layoutHeight = b - t; 197 | 198 | // Computes height and width for potentially doing fit width. 199 | int childWidth = layoutWidth; 200 | int childHeight = (int)(((float)layoutWidth / (float)width) * height); 201 | 202 | // If height is too tall using fit width, does fit height instead. 203 | if (childHeight > layoutHeight) 204 | { 205 | childHeight = layoutHeight; 206 | childWidth = (int)(((float)layoutHeight / (float)height) * width); 207 | } 208 | 209 | for (int i = 0; i < ChildCount; ++i) 210 | { 211 | 212 | GetChildAt(i).Layout(0, 0, childWidth, childHeight); 213 | } 214 | 215 | try 216 | { 217 | StartIfReady(); 218 | } 219 | catch (Exception e) 220 | { 221 | Log.Error(TAG, "Could not start camera source.", e); 222 | } 223 | } 224 | } 225 | 226 | } -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/CustomControls/GraphicOverlay.cs: -------------------------------------------------------------------------------- 1 |  2 | /* 3 | * Ported to C# from https://github.com/googlesamples/android-vision/tree/master/visionSamples/FaceTracker 4 | * Ported by Nish Anil (Nish@microsoft.com) 5 | * 6 | * Copyright (C) The Android Open Source Project 7 | * 8 | * Licensed under the Apache License, Version 2.0 (the "License"); 9 | * you may not use this file except in compliance with the License. 10 | * You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | using System; 22 | using System.Collections.Generic; 23 | using System.Linq; 24 | using System.Text; 25 | 26 | using Android.App; 27 | using Android.Content; 28 | using Android.OS; 29 | using Android.Runtime; 30 | using Android.Views; 31 | using Android.Widget; 32 | using Android.Gms.Vision; 33 | using Android.Util; 34 | using Android.Graphics; 35 | 36 | namespace LiveCam.Droid 37 | { 38 | /** 39 | * A view which renders a series of custom graphics to be overlayed on top of an associated preview 40 | * (i.e., the camera preview). The creator can add graphics objects, update the objects, and remove 41 | * them, triggering the appropriate drawing and invalidation within the view.

42 | * 43 | * Supports scaling and mirroring of the graphics relative the camera's preview properties. The 44 | * idea is that detection items are expressed in terms of a preview size, but need to be scaled up 45 | * to the full view size, and also mirrored in the case of the front-facing camera.

46 | * 47 | * Associated {@link Graphic} items should use the following methods to convert to view coordinates 48 | * for the graphics that are drawn: 49 | *

    50 | *
  1. {@link Graphic#scaleX(float)} and {@link Graphic#scaleY(float)} adjust the size of the 51 | * supplied value from the preview scale to the view scale.
  2. 52 | *
  3. {@link Graphic#translateX(float)} and {@link Graphic#translateY(float)} adjust the coordinate 53 | * from the preview's coordinate system to the view coordinate system.
  4. 54 | *
55 | */ 56 | public class GraphicOverlay : View 57 | { 58 | private Object mLock = new Object(); 59 | private int mPreviewWidth; 60 | private float mWidthScaleFactor = 1.0f; 61 | private int mPreviewHeight; 62 | private float mHeightScaleFactor = 1.0f; 63 | private CameraFacing mFacing = CameraFacing.Front; 64 | private HashSet mGraphics = new HashSet(); 65 | 66 | public int PreviewWidth { get => mPreviewWidth; set => mPreviewWidth = value; } 67 | public float WidthScaleFactor { get => mWidthScaleFactor; set => mWidthScaleFactor = value; } 68 | public int PreviewHeight { get => mPreviewHeight; set => mPreviewHeight = value; } 69 | public float HeightScaleFactor { get => mHeightScaleFactor; set => mHeightScaleFactor = value; } 70 | public CameraFacing CameraFacing { get => mFacing; set => mFacing = value; } 71 | 72 | public GraphicOverlay(Context context, IAttributeSet attrs) : base(context, attrs) 73 | { 74 | 75 | } 76 | 77 | /// 78 | /// Removes all graphics from the overlay. 79 | /// 80 | public void Clear() 81 | { 82 | lock(mLock) { 83 | mGraphics.Clear(); 84 | } 85 | PostInvalidate(); 86 | } 87 | 88 | /// 89 | /// Adds a graphic to the overlay. 90 | /// 91 | /// 92 | public void Add(Graphic graphic) 93 | { 94 | lock(mLock) { 95 | mGraphics.Add(graphic); 96 | } 97 | PostInvalidate(); 98 | } 99 | 100 | /// 101 | /// Removes a graphic from the overlay. 102 | /// 103 | /// 104 | public void Remove(Graphic graphic) 105 | { 106 | lock(mLock) { 107 | mGraphics.Remove(graphic); 108 | } 109 | PostInvalidate(); 110 | } 111 | 112 | /// 113 | /// Sets the camera attributes for size and facing direction, which informs how to transform image coordinates later. 114 | /// 115 | /// 116 | /// 117 | /// 118 | public void SetCameraInfo(int previewWidth, int previewHeight, CameraFacing facing) 119 | { 120 | lock(mLock) { 121 | PreviewWidth = previewWidth; 122 | PreviewHeight = previewHeight; 123 | CameraFacing = facing; 124 | } 125 | PostInvalidate(); 126 | } 127 | 128 | public override void Draw(Canvas canvas) 129 | { 130 | base.Draw(canvas); 131 | lock(mLock) { 132 | if ((PreviewWidth != 0) && (PreviewHeight != 0)) 133 | { 134 | WidthScaleFactor = (float)canvas.Width / (float)PreviewWidth; 135 | HeightScaleFactor = (float)canvas.Height / (float)PreviewHeight; 136 | } 137 | 138 | foreach (Graphic graphic in mGraphics) 139 | { 140 | graphic.Draw(canvas); 141 | } 142 | } 143 | } 144 | } 145 | 146 | /** 147 | * Base class for a custom graphics object to be rendered within the graphic overlay. Subclass 148 | * this and implement the {@link Graphic#draw(Canvas)} method to define the 149 | * graphics element. Add instances to the overlay using {@link GraphicOverlay#add(Graphic)}. 150 | */ 151 | public abstract class Graphic 152 | { 153 | private GraphicOverlay mOverlay; 154 | 155 | public Graphic(GraphicOverlay overlay) 156 | { 157 | mOverlay = overlay; 158 | } 159 | 160 | /** 161 | * Draw the graphic on the supplied canvas. Drawing should use the following methods to 162 | * convert to view coordinates for the graphics that are drawn: 163 | *
    164 | *
  1. {@link Graphic#scaleX(float)} and {@link Graphic#scaleY(float)} adjust the size of 165 | * the supplied value from the preview scale to the view scale.
  2. 166 | *
  3. {@link Graphic#translateX(float)} and {@link Graphic#translateY(float)} adjust the 167 | * coordinate from the preview's coordinate system to the view coordinate system.
  4. 168 | *
169 | * 170 | * @param canvas drawing canvas 171 | */ 172 | public abstract void Draw(Canvas canvas); 173 | 174 | /** 175 | * Adjusts a horizontal value of the supplied value from the preview scale to the view 176 | * scale. 177 | */ 178 | public float ScaleX(float horizontal) 179 | { 180 | return horizontal * mOverlay.WidthScaleFactor; 181 | } 182 | 183 | /** 184 | * Adjusts a vertical value of the supplied value from the preview scale to the view scale. 185 | */ 186 | public float ScaleY(float vertical) 187 | { 188 | return vertical * mOverlay.HeightScaleFactor; 189 | } 190 | 191 | /** 192 | * Adjusts the x coordinate from the preview's coordinate system to the view coordinate 193 | * system. 194 | */ 195 | public float TranslateX(float x) 196 | { 197 | if (mOverlay.CameraFacing == CameraFacing.Front) 198 | { 199 | return mOverlay.Width - ScaleX(x); 200 | } 201 | else 202 | { 203 | return ScaleX(x); 204 | } 205 | } 206 | 207 | /** 208 | * Adjusts the y coordinate from the preview's coordinate system to the view coordinate 209 | * system. 210 | */ 211 | public float TranslateY(float y) 212 | { 213 | return ScaleY(y); 214 | } 215 | 216 | public void PostInvalidate() 217 | { 218 | mOverlay.PostInvalidate(); 219 | } 220 | } 221 | } -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/FaceGraphic.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | using Android.App; 7 | using Android.Content; 8 | using Android.Graphics; 9 | using Android.OS; 10 | using Android.Runtime; 11 | using Android.Views; 12 | using Android.Widget; 13 | using Android.Gms.Vision.Faces; 14 | 15 | namespace LiveCam.Droid 16 | { 17 | public class FaceGraphic : Graphic 18 | { 19 | private static readonly float FACE_POSITION_RADIUS = 10.0f; 20 | private static readonly float ID_TEXT_SIZE = 40.0f; 21 | private static readonly float ID_Y_OFFSET = 50.0f; 22 | private static readonly float ID_X_OFFSET = -50.0f; 23 | private static readonly float BOX_STROKE_WIDTH = 5.0f; 24 | 25 | private static Color[] COLOR_CHOICES = { 26 | Color.Blue, 27 | Color.Cyan, 28 | Color.Green, 29 | Color.Magenta, 30 | Color.Red, 31 | Color.White, 32 | Color.Yellow 33 | }; 34 | private static int mCurrentColorIndex = 0; 35 | 36 | private Paint mFacePositionPaint; 37 | private Paint mIdPaint; 38 | private Paint mBoxPaint; 39 | 40 | private volatile Face mFace; 41 | private int mFaceId; 42 | private float mFaceHappiness; 43 | 44 | public FaceGraphic(GraphicOverlay overlay) : base(overlay) 45 | { 46 | mCurrentColorIndex = (mCurrentColorIndex + 1) % COLOR_CHOICES.Length; 47 | var selectedColor = COLOR_CHOICES[mCurrentColorIndex]; 48 | 49 | mFacePositionPaint = new Paint() 50 | { 51 | Color = selectedColor 52 | }; 53 | mIdPaint = new Paint() 54 | { 55 | Color = selectedColor, 56 | TextSize = ID_TEXT_SIZE 57 | }; 58 | mBoxPaint = new Paint() 59 | { 60 | Color = selectedColor 61 | }; 62 | mBoxPaint.SetStyle(Paint.Style.Stroke); 63 | mBoxPaint.StrokeWidth = BOX_STROKE_WIDTH; 64 | } 65 | public void SetId(int id) 66 | { 67 | mFaceId = id; 68 | } 69 | 70 | 71 | /** 72 | * Updates the face instance from the detection of the most recent frame. Invalidates the 73 | * relevant portions of the overlay to trigger a redraw. 74 | */ 75 | public void UpdateFace(Face face) 76 | { 77 | mFace = face; 78 | PostInvalidate(); 79 | } 80 | 81 | public override void Draw(Canvas canvas) 82 | { 83 | Face face = mFace; 84 | if (face == null) 85 | { 86 | return; 87 | } 88 | 89 | // Draws a circle at the position of the detected face, with the face's track id below. 90 | float x = TranslateX(face.Position.X + face.Width / 2); 91 | float y = TranslateY(face.Position.Y + face.Height / 2); 92 | //canvas.DrawCircle(x, y, FACE_POSITION_RADIUS, mFacePositionPaint); 93 | 94 | //HACK: Demo only 95 | if(!string.IsNullOrEmpty(MainActivity.GreetingsText)) 96 | 97 | canvas.DrawText(MainActivity.GreetingsText, x + ID_X_OFFSET, y + ID_Y_OFFSET, mIdPaint); 98 | //canvas.DrawText("happiness: " + Math.Round(face.IsSmilingProbability, 2).ToString(), x - ID_X_OFFSET, y - ID_Y_OFFSET, mIdPaint); 99 | //canvas.DrawText("right eye: " + Math.Round(face.IsRightEyeOpenProbability, 2).ToString(), x + ID_X_OFFSET * 2, y + ID_Y_OFFSET * 2, mIdPaint); 100 | //canvas.DrawText("left eye: " + Math.Round(face.IsLeftEyeOpenProbability, 2).ToString(), x - ID_X_OFFSET * 2, y - ID_Y_OFFSET * 2, mIdPaint); 101 | 102 | // Draws a bounding box around the face. 103 | float xOffset = ScaleX(face.Width / 2.0f); 104 | float yOffset = ScaleY(face.Height / 2.0f); 105 | float left = x - xOffset; 106 | float top = y - yOffset; 107 | float right = x + xOffset; 108 | float bottom = y + yOffset; 109 | canvas.DrawRect(left, top, right, bottom, mBoxPaint); 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/GettingStarted.Xamarin: -------------------------------------------------------------------------------- 1 | 2 | GS\Android\CS\AndroidApp\GettingStarted.html 3 | false 4 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/MainActivity.cs: -------------------------------------------------------------------------------- 1 | using Android.App; 2 | using Android.Widget; 3 | using Android.OS; 4 | using Android.Gms.Vision; 5 | using Android.Support.V4.App; 6 | using Android.Support.V7.App; 7 | 8 | using Android.Util; 9 | using Android; 10 | using Android.Support.Design.Widget; 11 | using Android.Content; 12 | using Android.Gms.Vision.Faces; 13 | using Java.Lang; 14 | using System; 15 | using Android.Runtime; 16 | using static Android.Gms.Vision.MultiProcessor; 17 | using Android.Content.PM; 18 | using Android.Gms.Common; 19 | using LiveCam.Shared; 20 | using System.Threading.Tasks; 21 | using ServiceHelpers; 22 | 23 | namespace LiveCam.Droid 24 | { 25 | [Activity(Label = "LiveCam.Droid", MainLauncher = true, Icon = "@drawable/icon", Theme = "@style/Theme.AppCompat.NoActionBar", ScreenOrientation = ScreenOrientation.FullSensor)] 26 | public class MainActivity : AppCompatActivity, IFactory 27 | { 28 | private static readonly string TAG = "FaceTracker"; 29 | 30 | private CameraSource mCameraSource = null; 31 | 32 | private CameraSourcePreview mPreview; 33 | private GraphicOverlay mGraphicOverlay; 34 | 35 | 36 | public static string GreetingsText 37 | { 38 | get; 39 | set; 40 | } 41 | 42 | private static readonly int RC_HANDLE_GMS = 9001; 43 | // permission request codes need to be < 256 44 | private static readonly int RC_HANDLE_CAMERA_PERM = 2; 45 | 46 | protected async override void OnCreate(Bundle bundle) 47 | { 48 | base.OnCreate(bundle); 49 | 50 | // Set our view from the "main" layout resource 51 | SetContentView(Resource.Layout.Main); 52 | 53 | mPreview = FindViewById(Resource.Id.preview); 54 | mGraphicOverlay = FindViewById(Resource.Id.faceOverlay); 55 | //greetingsText = FindViewById(Resource.Id.greetingsTextView); 56 | 57 | 58 | if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == Permission.Granted) 59 | { 60 | CreateCameraSource(); 61 | LiveCamHelper.Init(); 62 | LiveCamHelper.GreetingsCallback = (s) => { RunOnUiThread(()=> GreetingsText = s ); }; 63 | await LiveCamHelper.RegisterFaces(); 64 | } 65 | else { RequestCameraPermission(); } 66 | 67 | 68 | } 69 | 70 | protected override void OnResume() 71 | { 72 | base.OnResume(); 73 | StartCameraSource(); 74 | 75 | 76 | 77 | } 78 | 79 | protected override void OnPause() 80 | { 81 | base.OnPause(); 82 | mPreview.Stop(); 83 | } 84 | 85 | protected override void OnDestroy() 86 | { 87 | base.OnDestroy(); 88 | if (mCameraSource != null) 89 | { 90 | mCameraSource.Release(); 91 | } 92 | } 93 | 94 | private void RequestCameraPermission() 95 | { 96 | Log.Warn(TAG, "Camera permission is not granted. Requesting permission"); 97 | 98 | var permissions = new string[] { Manifest.Permission.Camera }; 99 | 100 | if (!ActivityCompat.ShouldShowRequestPermissionRationale(this, 101 | Manifest.Permission.Camera)) 102 | { 103 | ActivityCompat.RequestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM); 104 | return; 105 | } 106 | 107 | Snackbar.Make(mGraphicOverlay, Resource.String.permission_camera_rationale, 108 | Snackbar.LengthIndefinite) 109 | .SetAction(Resource.String.ok, (o) => { ActivityCompat.RequestPermissions(this, permissions, RC_HANDLE_CAMERA_PERM); }) 110 | .Show(); 111 | } 112 | 113 | /** 114 | * Creates and starts the camera. Note that this uses a higher resolution in comparison 115 | * to other detection examples to enable the barcode detector to detect small barcodes 116 | * at long distances. 117 | */ 118 | private void CreateCameraSource() 119 | { 120 | 121 | var context = Application.Context; 122 | FaceDetector detector = new FaceDetector.Builder(context) 123 | .SetClassificationType(ClassificationType.All) 124 | .Build(); 125 | 126 | detector.SetProcessor( 127 | new MultiProcessor.Builder(this) 128 | .Build()); 129 | 130 | if (!detector.IsOperational) 131 | { 132 | // Note: The first time that an app using face API is installed on a device, GMS will 133 | // download a native library to the device in order to do detection. Usually this 134 | // completes before the app is run for the first time. But if that download has not yet 135 | // completed, then the above call will not detect any faces. 136 | // 137 | // isOperational() can be used to check if the required native library is currently 138 | // available. The detector will automatically become operational once the library 139 | // download completes on device. 140 | Log.Warn(TAG, "Face detector dependencies are not yet available."); 141 | } 142 | 143 | mCameraSource = new CameraSource.Builder(context, detector) 144 | .SetRequestedPreviewSize(640, 480) 145 | .SetFacing(CameraFacing.Back) 146 | .SetRequestedFps(30.0f) 147 | .Build(); 148 | 149 | 150 | } 151 | 152 | /** 153 | * Starts or restarts the camera source, if it exists. If the camera source doesn't exist yet 154 | * (e.g., because onResume was called before the camera source was created), this will be called 155 | * again when the camera source is created. 156 | */ 157 | private void StartCameraSource() 158 | { 159 | 160 | // check that the device has play services available. 161 | int code = GoogleApiAvailability.Instance.IsGooglePlayServicesAvailable( 162 | this.ApplicationContext); 163 | if (code != ConnectionResult.Success) 164 | { 165 | Dialog dlg = 166 | GoogleApiAvailability.Instance.GetErrorDialog(this, code, RC_HANDLE_GMS); 167 | dlg.Show(); 168 | } 169 | 170 | if (mCameraSource != null) 171 | { 172 | try 173 | { 174 | mPreview.Start(mCameraSource, mGraphicOverlay); 175 | } 176 | catch (System.Exception e) 177 | { 178 | Log.Error(TAG, "Unable to start camera source.", e); 179 | mCameraSource.Release(); 180 | mCameraSource = null; 181 | } 182 | } 183 | } 184 | public Tracker Create(Java.Lang.Object item) 185 | { 186 | return new GraphicFaceTracker(mGraphicOverlay, mCameraSource); 187 | } 188 | 189 | 190 | public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Permission[] grantResults) 191 | { 192 | if (requestCode != RC_HANDLE_CAMERA_PERM) 193 | { 194 | Log.Debug(TAG, "Got unexpected permission result: " + requestCode); 195 | base.OnRequestPermissionsResult(requestCode, permissions, grantResults); 196 | 197 | return; 198 | } 199 | 200 | if (grantResults.Length != 0 && grantResults[0] == Permission.Granted) 201 | { 202 | Log.Debug(TAG, "Camera permission granted - initialize the camera source"); 203 | // we have permission, so create the camerasource 204 | CreateCameraSource(); 205 | return; 206 | } 207 | 208 | Log.Error(TAG, "Permission not granted: results len = " + grantResults.Length + 209 | " Result code = " + (grantResults.Length > 0 ? grantResults[0].ToString() : "(empty)")); 210 | 211 | 212 | var builder = new Android.Support.V7.App.AlertDialog.Builder(this); 213 | builder.SetTitle("LiveCam") 214 | .SetMessage(Resource.String.no_camera_permission) 215 | .SetPositiveButton(Resource.String.ok, (o, e) => Finish()) 216 | .Show(); 217 | 218 | } 219 | } 220 | 221 | 222 | class GraphicFaceTracker : Tracker, CameraSource.IPictureCallback 223 | { 224 | private GraphicOverlay mOverlay; 225 | private FaceGraphic mFaceGraphic; 226 | private CameraSource mCameraSource = null; 227 | private bool isProcessing = false; 228 | 229 | public GraphicFaceTracker(GraphicOverlay overlay, CameraSource cameraSource =null) 230 | { 231 | mOverlay = overlay; 232 | mFaceGraphic = new FaceGraphic(overlay); 233 | mCameraSource = cameraSource; 234 | } 235 | 236 | public override void OnNewItem(int id, Java.Lang.Object item) 237 | { 238 | mFaceGraphic.SetId(id); 239 | if (mCameraSource != null && !isProcessing) 240 | mCameraSource.TakePicture(null, this); 241 | } 242 | 243 | public override void OnUpdate(Detector.Detections detections, Java.Lang.Object item) 244 | { 245 | var face = item as Face; 246 | mOverlay.Add(mFaceGraphic); 247 | mFaceGraphic.UpdateFace(face); 248 | 249 | } 250 | 251 | public override void OnMissing(Detector.Detections detections) 252 | { 253 | mOverlay.Remove(mFaceGraphic); 254 | 255 | } 256 | 257 | public override void OnDone() 258 | { 259 | mOverlay.Remove(mFaceGraphic); 260 | 261 | } 262 | 263 | public void OnPictureTaken(byte[] data) 264 | { 265 | Task.Run(async () => 266 | { 267 | try 268 | { 269 | isProcessing = true; 270 | 271 | Console.WriteLine("face detected: "); 272 | 273 | var imageAnalyzer = new ImageAnalyzer(data); 274 | await LiveCamHelper.ProcessCameraCapture(imageAnalyzer); 275 | 276 | } 277 | 278 | finally 279 | { 280 | isProcessing = false; 281 | 282 | 283 | } 284 | 285 | }); 286 | } 287 | } 288 | 289 | } 290 | 291 | 292 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/Properties/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | using Android.App; 5 | 6 | // General Information about an assembly is controlled through the following 7 | // set of attributes. Change these attribute values to modify the information 8 | // associated with an assembly. 9 | [assembly: AssemblyTitle("LiveCam.Droid")] 10 | [assembly: AssemblyDescription("")] 11 | [assembly: AssemblyConfiguration("")] 12 | [assembly: AssemblyCompany("")] 13 | [assembly: AssemblyProduct("LiveCam.Droid")] 14 | [assembly: AssemblyCopyright("Copyright © 2017")] 15 | [assembly: AssemblyTrademark("")] 16 | [assembly: AssemblyCulture("")] 17 | [assembly: ComVisible(false)] 18 | 19 | // Version information for an assembly consists of the following four values: 20 | // 21 | // Major Version 22 | // Minor Version 23 | // Build Number 24 | // Revision 25 | // 26 | // You can specify all the values or you can default the Build and Revision Numbers 27 | // by using the '*' as shown below: 28 | // [assembly: AssemblyVersion("1.0.*")] 29 | [assembly: AssemblyVersion("1.0.0.0")] 30 | [assembly: AssemblyFileVersion("1.0.0.0")] 31 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/Resources/AboutResources.txt: -------------------------------------------------------------------------------- 1 | Images, layout descriptions, binary blobs and string dictionaries can be included 2 | in your application as resource files. Various Android APIs are designed to 3 | operate on the resource IDs instead of dealing with images, strings or binary blobs 4 | directly. 5 | 6 | For example, a sample Android app that contains a user interface layout (main.axml), 7 | an internationalization string table (strings.xml) and some icons (drawable-XXX/icon.png) 8 | would keep its resources in the "Resources" directory of the application: 9 | 10 | Resources/ 11 | drawable/ 12 | icon.png 13 | 14 | layout/ 15 | main.axml 16 | 17 | values/ 18 | strings.xml 19 | 20 | In order to get the build system to recognize Android resources, set the build action to 21 | "AndroidResource". The native Android APIs do not operate directly with filenames, but 22 | instead operate on resource IDs. When you compile an Android application that uses resources, 23 | the build system will package the resources for distribution and generate a class called "R" 24 | (this is an Android convention) that contains the tokens for each one of the resources 25 | included. For example, for the above Resources layout, this is what the R class would expose: 26 | 27 | public class R { 28 | public class drawable { 29 | public const int icon = 0x123; 30 | } 31 | 32 | public class layout { 33 | public const int main = 0x456; 34 | } 35 | 36 | public class strings { 37 | public const int first_string = 0xabc; 38 | public const int second_string = 0xbcd; 39 | } 40 | } 41 | 42 | You would then use R.drawable.icon to reference the drawable/icon.png file, or R.layout.main 43 | to reference the layout/main.axml file, or R.strings.first_string to reference the first 44 | string in the dictionary file values/strings.xml. -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/Resources/drawable/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nishanil/Cogs/a4b8735abae99f86f882adbb76bc014728f6b8ac/LiveCam/LiveCam.Droid/Resources/drawable/Icon.png -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/Resources/layout/Main.axml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 12 | 16 | 17 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/Resources/values/Strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello World, Click Me! 4 | LiveCam 5 | OK 6 | Access to the camera is needed for detection 7 | This application cannot run because it does not have the camera permission. The application will now exit. 8 | Face detector dependencies cannot be downloaded due to low device storage 9 | 10 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Droid/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Shared/LiveCam.Shared.projitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | b0ae8996-b543-4880-904e-129e5bf8174d 7 | 8 | 9 | LiveCam.Shared 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Shared/LiveCam.Shared.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | b0ae8996-b543-4880-904e-129e5bf8174d 5 | 14.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /LiveCam/LiveCam.Shared/LiveCamHelper.cs: -------------------------------------------------------------------------------- 1 |  2 | using Microsoft.ProjectOxford.Face; 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 | 10 | namespace LiveCam.Shared 11 | { 12 | public static class LiveCamHelper 13 | { 14 | public static bool IsFaceRegistered { get; set; } 15 | 16 | public static bool IsInitialized { get; set; } 17 | 18 | public static string WorkspaceKey 19 | { 20 | get; 21 | set; 22 | } 23 | public static Action GreetingsCallback { get => greetingsCallback; set => greetingsCallback = value; } 24 | 25 | private static Action greetingsCallback; 26 | 27 | public static void Init(Action throttled = null) 28 | { 29 | FaceServiceHelper.ApiKey = "b1843365b41247538cffb304d36609b3"; 30 | if(throttled!=null) 31 | FaceServiceHelper.Throttled += throttled; 32 | 33 | WorkspaceKey = Guid.NewGuid().ToString(); 34 | ImageAnalyzer.PeopleGroupsUserDataFilter = WorkspaceKey; 35 | FaceListManager.FaceListsUserDataFilter = WorkspaceKey; 36 | 37 | IsInitialized = true; 38 | } 39 | 40 | public static async Task RegisterFaces() 41 | { 42 | 43 | try 44 | { 45 | var persongroupId = Guid.NewGuid().ToString(); 46 | await FaceServiceHelper.CreatePersonGroupAsync(persongroupId, 47 | "Xamarin", 48 | WorkspaceKey); 49 | await FaceServiceHelper.CreatePersonAsync(persongroupId, "Albert Einstein"); 50 | 51 | var personsInGroup = await FaceServiceHelper.GetPersonsAsync(persongroupId); 52 | 53 | await FaceServiceHelper.AddPersonFaceAsync(persongroupId, personsInGroup[0].PersonId, 54 | "https://upload.wikimedia.org/wikipedia/commons/d/d3/Albert_Einstein_Head.jpg", null, null); 55 | 56 | await FaceServiceHelper.TrainPersonGroupAsync(persongroupId); 57 | 58 | 59 | IsFaceRegistered = true; 60 | 61 | 62 | } 63 | catch (FaceAPIException ex) 64 | 65 | { 66 | Console.WriteLine(ex.Message); 67 | IsFaceRegistered = false; 68 | 69 | } 70 | 71 | } 72 | 73 | public static async Task ProcessCameraCapture(ImageAnalyzer e) 74 | { 75 | 76 | DateTime start = DateTime.Now; 77 | 78 | await e.DetectFacesAsync(); 79 | 80 | if (e.DetectedFaces.Any()) 81 | { 82 | await e.IdentifyFacesAsync(); 83 | string greetingsText = GetGreettingFromFaces(e); 84 | 85 | if (e.IdentifiedPersons.Any()) 86 | { 87 | 88 | if (greetingsCallback != null) 89 | { 90 | DisplayMessage(greetingsText); 91 | } 92 | 93 | Console.WriteLine(greetingsText); 94 | } 95 | else 96 | { 97 | DisplayMessage("No Idea, who you're.. Register your face."); 98 | 99 | Console.WriteLine("No Idea"); 100 | 101 | } 102 | } 103 | else 104 | { 105 | // DisplayMessage("No face detected."); 106 | 107 | Console.WriteLine("No Face "); 108 | 109 | } 110 | 111 | TimeSpan latency = DateTime.Now - start; 112 | var latencyString = string.Format("Face API latency: {0}ms", (int)latency.TotalMilliseconds); 113 | Console.WriteLine(latencyString); 114 | } 115 | 116 | private static string GetGreettingFromFaces(ImageAnalyzer img) 117 | { 118 | if (img.IdentifiedPersons.Any()) 119 | { 120 | string names = img.IdentifiedPersons.Count() > 1 ? string.Join(", ", img.IdentifiedPersons.Select(p => p.Person.Name)) : img.IdentifiedPersons.First().Person.Name; 121 | 122 | if (img.DetectedFaces.Count() > img.IdentifiedPersons.Count()) 123 | { 124 | return string.Format("Welcome back, {0} and company!", names); 125 | } 126 | else 127 | { 128 | return string.Format("Welcome back, {0}!", names); 129 | } 130 | } 131 | else 132 | { 133 | if (img.DetectedFaces.Count() > 1) 134 | { 135 | return "Hi everyone! If I knew any of you by name I would say it..."; 136 | } 137 | else 138 | { 139 | return "Hi there! If I knew you by name I would say it..."; 140 | } 141 | } 142 | } 143 | 144 | static void DisplayMessage(string greetingsText) 145 | { 146 | greetingsCallback?.Invoke(greetingsText); 147 | } 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /LiveCam/LiveCam/AppDelegate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Foundation; 3 | using ServiceHelpers; 4 | using UIKit; 5 | 6 | namespace LiveCam 7 | { 8 | // The UIApplicationDelegate for the application. This class is responsible for launching the 9 | // User Interface of the application, as well as listening (and optionally responding) to 10 | // application events from iOS. 11 | [Register("AppDelegate")] 12 | public class AppDelegate : UIApplicationDelegate 13 | { 14 | 15 | 16 | // class-level declarations 17 | 18 | public override UIWindow Window 19 | { 20 | get; 21 | set; 22 | } 23 | public static string WorkspaceKey 24 | { 25 | get; 26 | set; 27 | } 28 | public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) 29 | { 30 | // Override point for customization after application launch. 31 | // If not required for your application you can safely delete this method 32 | 33 | 34 | //TODO: Get from Settings 35 | FaceServiceHelper.ApiKey = "b1843365b41247538cffb304d36609b3"; 36 | 37 | FaceServiceHelper.Throttled += FaceServiceHelper_Throttled; 38 | 39 | WorkspaceKey = Guid.NewGuid().ToString(); 40 | ImageAnalyzer.PeopleGroupsUserDataFilter = WorkspaceKey; 41 | FaceListManager.FaceListsUserDataFilter = WorkspaceKey; 42 | 43 | 44 | return true; 45 | } 46 | 47 | void FaceServiceHelper_Throttled() 48 | { 49 | 50 | UIAlertController okayAlertController = UIAlertController.Create("Intelligent Kios", "Face API Throttled", UIAlertControllerStyle.Alert); 51 | okayAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); 52 | 53 | Window.RootViewController.PresentViewController(okayAlertController, true, null); 54 | 55 | } 56 | 57 | 58 | 59 | public override void OnResignActivation(UIApplication application) 60 | { 61 | // Invoked when the application is about to move from active to inactive state. 62 | // This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) 63 | // or when the user quits the application and it begins the transition to the background state. 64 | // Games should use this method to pause the game. 65 | } 66 | 67 | 68 | public override void DidEnterBackground(UIApplication application) 69 | { 70 | // Use this method to release shared resources, save user data, invalidate timers and store the application state. 71 | // If your application supports background exection this method is called instead of WillTerminate when the user quits. 72 | } 73 | 74 | public override void WillEnterForeground(UIApplication application) 75 | { 76 | // Called as part of the transiton from background to active state. 77 | // Here you can undo many of the changes made on entering the background. 78 | } 79 | 80 | public override void OnActivated(UIApplication application) 81 | { 82 | // Restart any tasks that were paused (or not yet started) while the application was inactive. 83 | // If the application was previously in the background, optionally refresh the user interface. 84 | } 85 | 86 | public override void WillTerminate(UIApplication application) 87 | { 88 | // Called when the application is about to terminate. Save data, if needed. See also DidEnterBackground. 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /LiveCam/LiveCam/Entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /LiveCam/LiveCam/GettingStarted.Xamarin: -------------------------------------------------------------------------------- 1 | 2 | GS\iOS\CS\iOSApp\GettingStarted.html 3 | false 4 | -------------------------------------------------------------------------------- /LiveCam/LiveCam/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDisplayName 6 | LiveCam 7 | CFBundleIdentifier 8 | com.nnish.livecam 9 | CFBundleShortVersionString 10 | 1.0 11 | CFBundleVersion 12 | 1.0 13 | LSRequiresIPhoneOS 14 | 15 | MinimumOSVersion 16 | 17 | UIDeviceFamily 18 | 19 | 1 20 | 2 21 | 22 | UILaunchStoryboardName 23 | LaunchScreen 24 | UIMainStoryboardFile 25 | Main 26 | UIMainStoryboardFile~ipad 27 | Main 28 | UIRequiredDeviceCapabilities 29 | 30 | armv7 31 | 32 | UISupportedInterfaceOrientations 33 | 34 | UIInterfaceOrientationPortrait 35 | 36 | UISupportedInterfaceOrientations~ipad 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | NSCameraUsageDescription 43 | For Face Detection 44 | CFBundleName 45 | LiveCam 46 | 47 | 48 | -------------------------------------------------------------------------------- /LiveCam/LiveCam/LiveCam.iOS.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | iPhoneSimulator 6 | {212ABB9C-5F35-463F-9A27-8F39811C4128} 7 | {FEACFBD2-3405-455C-9665-78FE426C6842};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 8 | Exe 9 | LiveCam 10 | Resources 11 | LiveCam 12 | 13 | 14 | true 15 | full 16 | false 17 | bin\iPhoneSimulator\Debug 18 | DEBUG 19 | prompt 20 | 4 21 | false 22 | x86_64 23 | None 24 | true 25 | 26 | 27 | none 28 | true 29 | bin\iPhoneSimulator\Release 30 | prompt 31 | 4 32 | None 33 | x86_64 34 | false 35 | 36 | 37 | true 38 | full 39 | false 40 | bin\iPhone\Debug 41 | DEBUG 42 | prompt 43 | 4 44 | false 45 | ARMv7, ARM64 46 | Entitlements.plist 47 | iPhone Developer 48 | true 49 | 50 | 51 | none 52 | true 53 | bin\iPhone\Release 54 | prompt 55 | 4 56 | Entitlements.plist 57 | ARMv7, ARM64 58 | false 59 | iPhone Developer 60 | 61 | 62 | none 63 | True 64 | bin\iPhone\Ad-Hoc 65 | prompt 66 | 4 67 | False 68 | ARMv7, ARM64 69 | Entitlements.plist 70 | True 71 | Automatic:AdHoc 72 | iPhone Distribution 73 | 74 | 75 | none 76 | True 77 | bin\iPhone\AppStore 78 | prompt 79 | 4 80 | False 81 | ARMv7, ARM64 82 | Entitlements.plist 83 | Automatic:AppStore 84 | iPhone Distribution 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | ViewController.cs 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | {5d9320af-a9e4-48e3-89bc-9f7f0954b298} 115 | ServiceHelpers 116 | 117 | 118 | {25D58BA5-660F-407B-803C-22B4547C09DC} 119 | Microsoft.ProjectOxford.Face 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /LiveCam/LiveCam/Main.cs: -------------------------------------------------------------------------------- 1 | using UIKit; 2 | 3 | namespace LiveCam 4 | { 5 | public class Application 6 | { 7 | // This is the main entry point of the application. 8 | static void Main(string[] args) 9 | { 10 | // if you want to use a different Application Delegate class from "AppDelegate" 11 | // you can specify it here. 12 | UIApplication.Main(args, null, "AppDelegate"); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /LiveCam/LiveCam/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /LiveCam/LiveCam/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("LiveCam")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("LiveCam")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("212abb9c-5f35-463f-9a27-8f39811c4128")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /LiveCam/LiveCam/Resources/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 21 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /LiveCam/LiveCam/Resources/square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nishanil/Cogs/a4b8735abae99f86f882adbb76bc014728f6b8ac/LiveCam/LiveCam/Resources/square.png -------------------------------------------------------------------------------- /LiveCam/LiveCam/UIExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using CoreGraphics; 3 | using UIKit; 4 | 5 | namespace LiveCam 6 | { 7 | public static class UIExtensions 8 | { 9 | public static UIImage ResizeImageWithAspectRatio(this UIImage sourceImage, float maxWidth, float maxHeight) 10 | { 11 | var sourceSize = sourceImage.Size; 12 | var maxResizeFactor = Math.Max(maxWidth / sourceSize.Width, maxHeight / sourceSize.Height); 13 | if (maxResizeFactor > 1) return sourceImage; 14 | var width = maxResizeFactor * sourceSize.Width; 15 | var height = maxResizeFactor * sourceSize.Height; 16 | UIGraphics.BeginImageContext(new CGSize(width, height)); 17 | sourceImage.Draw(new CGRect(0, 0, width, height)); 18 | var resultImage = UIGraphics.GetImageFromCurrentImageContext(); 19 | UIGraphics.EndImageContext(); 20 | return resultImage; 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /LiveCam/LiveCam/ViewController.designer.cs: -------------------------------------------------------------------------------- 1 | // WARNING 2 | // 3 | // This file has been generated automatically by Xamarin Studio from the outlets and 4 | // actions declared in your storyboard file. 5 | // Manual changes to this file will not be maintained. 6 | // 7 | using Foundation; 8 | using System; 9 | using System.CodeDom.Compiler; 10 | 11 | namespace LiveCam 12 | { 13 | [Register ("ViewController")] 14 | partial class ViewController 15 | { 16 | [Outlet] 17 | [GeneratedCode ("iOS Designer", "1.0")] 18 | UIKit.UILabel GreetingsLabel { get; set; } 19 | 20 | [Outlet] 21 | [GeneratedCode ("iOS Designer", "1.0")] 22 | UIKit.UIView HomeView { get; set; } 23 | 24 | void ReleaseDesignerOutlets () 25 | { 26 | if (GreetingsLabel != null) { 27 | GreetingsLabel.Dispose (); 28 | GreetingsLabel = null; 29 | } 30 | 31 | if (HomeView != null) { 32 | HomeView.Dispose (); 33 | HomeView = null; 34 | } 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /LiveCam/LiveCam/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/AddPersistedFaceResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | /// 39 | /// Represents face stored in FaceList or Person 40 | /// 41 | public class AddPersistedFaceResult 42 | { 43 | #region Properties 44 | 45 | /// 46 | /// Gets or sets the persisted face identifier. 47 | /// 48 | /// 49 | /// The persisted face identifier. 50 | /// 51 | public Guid PersistedFaceId 52 | { 53 | get; 54 | set; 55 | } 56 | 57 | #endregion Properties 58 | } 59 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/Candidate.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | /// 39 | /// The identified candidate entity. 40 | /// 41 | public class Candidate 42 | { 43 | #region Properties 44 | 45 | /// 46 | /// Gets or sets the person identifier. 47 | /// 48 | /// 49 | /// The person identifier. 50 | /// 51 | public Guid PersonId 52 | { 53 | get; 54 | set; 55 | } 56 | 57 | /// 58 | /// Gets or sets the confidence. 59 | /// 60 | /// 61 | /// The confidence. 62 | /// 63 | public double Confidence 64 | { 65 | get; 66 | set; 67 | } 68 | 69 | #endregion Properties 70 | } 71 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/ClientError.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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.Net; 36 | using System.Runtime.Serialization; 37 | 38 | namespace Microsoft.ProjectOxford.Face.Contract 39 | { 40 | /// 41 | /// Represents client error with detailed error message and error code 42 | /// 43 | [DataContract] 44 | public class ClientError 45 | { 46 | #region Constructors 47 | 48 | /// 49 | /// Initializes a new instance of the class 50 | /// 51 | public ClientError() 52 | { 53 | } 54 | 55 | #endregion Constructors 56 | 57 | #region Properties 58 | 59 | /// 60 | /// Gets or sets the detailed error message and error code 61 | /// 62 | [DataMember(Name = "error")] 63 | public ClientExceptionMessage Error 64 | { 65 | get; 66 | set; 67 | } 68 | 69 | #endregion Properties 70 | } 71 | 72 | /// 73 | /// Represents detailed error message and error code 74 | /// 75 | [DataContract] 76 | public class ClientExceptionMessage 77 | { 78 | #region Properties 79 | 80 | /// 81 | /// Gets or sets the detailed error code 82 | /// 83 | [DataMember(Name = "code")] 84 | public string ErrorCode 85 | { 86 | get; 87 | set; 88 | } 89 | 90 | /// 91 | /// Gets or sets the detailed error message 92 | /// 93 | [DataMember(Name = "message")] 94 | public string Message 95 | { 96 | get; 97 | set; 98 | } 99 | 100 | #endregion Properties 101 | } 102 | 103 | /// 104 | /// Represents client error with detailed error message and error code 105 | /// 106 | [DataContract] 107 | public class ServiceError 108 | { 109 | #region Constructors 110 | 111 | /// 112 | /// Initializes a new instance of the class 113 | /// 114 | public ServiceError() 115 | { 116 | } 117 | 118 | #endregion Constructors 119 | 120 | #region Properties 121 | 122 | /// 123 | /// Gets or sets the detailed error message and error code 124 | /// 125 | [DataMember(Name = "statusCode")] 126 | public string ErrorCode 127 | { 128 | get; 129 | set; 130 | } 131 | 132 | /// 133 | /// Gets or sets the detailed error message and error code 134 | /// 135 | [DataMember(Name = "message")] 136 | public string Message 137 | { 138 | get; 139 | set; 140 | } 141 | 142 | #endregion Properties 143 | } 144 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/CreatePersonResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | /// 39 | /// The class for person creation result. 40 | /// 41 | public class CreatePersonResult 42 | { 43 | #region Properties 44 | 45 | /// 46 | /// Gets or sets the person identifier. 47 | /// 48 | /// 49 | /// The person identifier. 50 | /// 51 | public Guid PersonId 52 | { 53 | get; 54 | set; 55 | } 56 | 57 | #endregion Properties 58 | } 59 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/Face.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | /// 39 | /// The detected face entity. 40 | /// 41 | public class Face 42 | { 43 | #region Properties 44 | 45 | /// 46 | /// Gets or sets the face identifier. 47 | /// 48 | /// 49 | /// The face identifier. 50 | /// 51 | public Guid FaceId 52 | { 53 | get; 54 | set; 55 | } 56 | 57 | /// 58 | /// Gets or sets the face rectangle. 59 | /// 60 | /// 61 | /// The face rectangle. 62 | /// 63 | public FaceRectangle FaceRectangle 64 | { 65 | get; 66 | set; 67 | } 68 | 69 | /// 70 | /// Gets or sets the face landmarks. 71 | /// 72 | /// 73 | /// The face landmarks. 74 | /// 75 | public FaceLandmarks FaceLandmarks 76 | { 77 | get; 78 | set; 79 | } 80 | 81 | /// 82 | /// Gets or sets the face attributes. 83 | /// 84 | /// 85 | /// The face attributes. 86 | /// 87 | public FaceAttributes FaceAttributes 88 | { 89 | get; 90 | set; 91 | } 92 | 93 | #endregion Properties 94 | } 95 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/FaceAttributes.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 Newtonsoft.Json.Converters; 36 | 37 | namespace Microsoft.ProjectOxford.Face.Contract 38 | { 39 | /// 40 | /// The face attributes class that holds Age/Gender/Head Pose/Smile/Facial Hair information. 41 | /// 42 | public class FaceAttributes 43 | { 44 | #region Properties 45 | 46 | /// 47 | /// Gets or sets the age value. 48 | /// 49 | /// 50 | /// The age value. 51 | /// 52 | public double Age 53 | { 54 | get; set; 55 | } 56 | 57 | /// 58 | /// Gets or sets the gender. 59 | /// 60 | /// 61 | /// The gender. 62 | /// 63 | public string Gender 64 | { 65 | get; set; 66 | } 67 | 68 | /// 69 | /// Gets or sets the head pose. 70 | /// 71 | /// 72 | /// The head pose. 73 | /// 74 | public HeadPose HeadPose 75 | { 76 | get; set; 77 | } 78 | 79 | /// 80 | /// Gets or sets the smile value. Represents the confidence of face is smiling. 81 | /// 82 | /// 83 | /// The smile value. 84 | /// 85 | public double Smile 86 | { 87 | get; set; 88 | } 89 | 90 | /// 91 | /// Gets or sets the facial hair. 92 | /// 93 | /// 94 | /// The facial hair. 95 | /// 96 | public FacialHair FacialHair 97 | { 98 | get; set; 99 | } 100 | 101 | /// 102 | /// Gets or sets the glasses type. 103 | /// 104 | /// 105 | /// The glasses type. 106 | /// 107 | [JsonConverter(typeof(StringEnumConverter))] 108 | public Glasses Glasses 109 | { 110 | get; set; 111 | } 112 | 113 | #endregion Properties 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/FaceLandmarks.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | namespace Microsoft.ProjectOxford.Face.Contract 35 | { 36 | /// 37 | /// The face landmarks class. 38 | /// 39 | public class FaceLandmarks 40 | { 41 | #region Properties 42 | 43 | /// 44 | /// Gets or sets the pupil left. 45 | /// 46 | /// 47 | /// The pupil left. 48 | /// 49 | public FeatureCoordinate PupilLeft 50 | { 51 | get; set; 52 | } 53 | 54 | /// 55 | /// Gets or sets the pupil right. 56 | /// 57 | /// 58 | /// The pupil right. 59 | /// 60 | public FeatureCoordinate PupilRight 61 | { 62 | get; set; 63 | } 64 | 65 | /// 66 | /// Gets or sets the nose tip. 67 | /// 68 | /// 69 | /// The nose tip. 70 | /// 71 | public FeatureCoordinate NoseTip 72 | { 73 | get; set; 74 | } 75 | 76 | /// 77 | /// Gets or sets the mouth left. 78 | /// 79 | /// 80 | /// The mouth left. 81 | /// 82 | public FeatureCoordinate MouthLeft 83 | { 84 | get; set; 85 | } 86 | 87 | /// 88 | /// Gets or sets the mouth right. 89 | /// 90 | /// 91 | /// The mouth right. 92 | /// 93 | public FeatureCoordinate MouthRight 94 | { 95 | get; set; 96 | } 97 | 98 | /// 99 | /// Gets or sets the eyebrow left outer. 100 | /// 101 | /// 102 | /// The eyebrow left outer. 103 | /// 104 | public FeatureCoordinate EyebrowLeftOuter 105 | { 106 | get; set; 107 | } 108 | 109 | /// 110 | /// Gets or sets the eyebrow left inner. 111 | /// 112 | /// 113 | /// The eyebrow left inner. 114 | /// 115 | public FeatureCoordinate EyebrowLeftInner 116 | { 117 | get; set; 118 | } 119 | 120 | /// 121 | /// Gets or sets the eye left outer. 122 | /// 123 | /// 124 | /// The eye left outer. 125 | /// 126 | public FeatureCoordinate EyeLeftOuter 127 | { 128 | get; set; 129 | } 130 | 131 | /// 132 | /// Gets or sets the eye left top. 133 | /// 134 | /// 135 | /// The eye left top. 136 | /// 137 | public FeatureCoordinate EyeLeftTop 138 | { 139 | get; set; 140 | } 141 | 142 | /// 143 | /// Gets or sets the eye left bottom. 144 | /// 145 | /// 146 | /// The eye left bottom. 147 | /// 148 | public FeatureCoordinate EyeLeftBottom 149 | { 150 | get; set; 151 | } 152 | 153 | /// 154 | /// Gets or sets the eye left inner. 155 | /// 156 | /// 157 | /// The eye left inner. 158 | /// 159 | public FeatureCoordinate EyeLeftInner 160 | { 161 | get; set; 162 | } 163 | 164 | /// 165 | /// Gets or sets the eyebrow right inner. 166 | /// 167 | /// 168 | /// The eyebrow right inner. 169 | /// 170 | public FeatureCoordinate EyebrowRightInner 171 | { 172 | get; set; 173 | } 174 | 175 | /// 176 | /// Gets or sets the eyebrow right outer. 177 | /// 178 | /// 179 | /// The eyebrow right outer. 180 | /// 181 | public FeatureCoordinate EyebrowRightOuter 182 | { 183 | get; set; 184 | } 185 | 186 | /// 187 | /// Gets or sets the eye right inner. 188 | /// 189 | /// 190 | /// The eye right inner. 191 | /// 192 | public FeatureCoordinate EyeRightInner 193 | { 194 | get; set; 195 | } 196 | 197 | /// 198 | /// Gets or sets the eye right top. 199 | /// 200 | /// 201 | /// The eye right top. 202 | /// 203 | public FeatureCoordinate EyeRightTop 204 | { 205 | get; set; 206 | } 207 | 208 | /// 209 | /// Gets or sets the eye right bottom. 210 | /// 211 | /// 212 | /// The eye right bottom. 213 | /// 214 | public FeatureCoordinate EyeRightBottom 215 | { 216 | get; set; 217 | } 218 | 219 | /// 220 | /// Gets or sets the eye right outer. 221 | /// 222 | /// 223 | /// The eye right outer. 224 | /// 225 | public FeatureCoordinate EyeRightOuter 226 | { 227 | get; set; 228 | } 229 | 230 | /// 231 | /// Gets or sets the nose root left. 232 | /// 233 | /// 234 | /// The nose root left. 235 | /// 236 | public FeatureCoordinate NoseRootLeft 237 | { 238 | get; set; 239 | } 240 | 241 | /// 242 | /// Gets or sets the nose root right. 243 | /// 244 | /// 245 | /// The nose root right. 246 | /// 247 | public FeatureCoordinate NoseRootRight 248 | { 249 | get; set; 250 | } 251 | 252 | /// 253 | /// Gets or sets the nose left alar top. 254 | /// 255 | /// 256 | /// The nose left alar top. 257 | /// 258 | public FeatureCoordinate NoseLeftAlarTop 259 | { 260 | get; set; 261 | } 262 | 263 | /// 264 | /// Gets or sets the nose right alar top. 265 | /// 266 | /// 267 | /// The nose right alar top. 268 | /// 269 | public FeatureCoordinate NoseRightAlarTop 270 | { 271 | get; set; 272 | } 273 | 274 | /// 275 | /// Gets or sets the nose left alar out tip. 276 | /// 277 | /// 278 | /// The nose left alar out tip. 279 | /// 280 | public FeatureCoordinate NoseLeftAlarOutTip 281 | { 282 | get; set; 283 | } 284 | 285 | /// 286 | /// Gets or sets the nose right alar out tip. 287 | /// 288 | /// 289 | /// The nose right alar out tip. 290 | /// 291 | public FeatureCoordinate NoseRightAlarOutTip 292 | { 293 | get; set; 294 | } 295 | 296 | /// 297 | /// Gets or sets the upper lip top. 298 | /// 299 | /// 300 | /// The upper lip top. 301 | /// 302 | public FeatureCoordinate UpperLipTop 303 | { 304 | get; set; 305 | } 306 | 307 | /// 308 | /// Gets or sets the upper lip bottom. 309 | /// 310 | /// 311 | /// The upper lip bottom. 312 | /// 313 | public FeatureCoordinate UpperLipBottom 314 | { 315 | get; set; 316 | } 317 | 318 | /// 319 | /// Gets or sets the under lip top. 320 | /// 321 | /// 322 | /// The under lip top. 323 | /// 324 | public FeatureCoordinate UnderLipTop 325 | { 326 | get; set; 327 | } 328 | 329 | /// 330 | /// Gets or sets the under lip bottom. 331 | /// 332 | /// 333 | /// The under lip bottom. 334 | /// 335 | public FeatureCoordinate UnderLipBottom 336 | { 337 | get; set; 338 | } 339 | 340 | #endregion Properties 341 | } 342 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/FaceList.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | namespace Microsoft.ProjectOxford.Face.Contract 35 | { 36 | /// 37 | /// The face list class 38 | /// 39 | public class FaceList : FaceListMetadata 40 | { 41 | #region Properties 42 | 43 | /// 44 | /// Gets or sets the persisted faces. 45 | /// 46 | /// 47 | /// The persisted faces. 48 | /// 49 | public PersonFace[] PersistedFaces 50 | { 51 | get; set; 52 | } 53 | 54 | #endregion Properties 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/FaceListMetadata.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | namespace Microsoft.ProjectOxford.Face.Contract 35 | { 36 | /// 37 | /// The face list metadata class. 38 | /// 39 | public class FaceListMetadata 40 | { 41 | #region Properties 42 | 43 | /// 44 | /// Gets or sets the face list identifier. 45 | /// 46 | /// 47 | /// The face list identifier. 48 | /// 49 | public string FaceListId 50 | { 51 | get; set; 52 | } 53 | 54 | /// 55 | /// Gets or sets the name. 56 | /// 57 | /// 58 | /// The name. 59 | /// 60 | public string Name 61 | { 62 | get; set; 63 | } 64 | 65 | /// 66 | /// Gets or sets the user data. 67 | /// 68 | /// 69 | /// The user data. 70 | /// 71 | public string UserData 72 | { 73 | get; set; 74 | } 75 | 76 | #endregion Properties 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/FaceMetadata.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | /// 39 | /// Face metadata class. 40 | /// 41 | public class FaceMetadata 42 | { 43 | #region Properties 44 | 45 | /// 46 | /// Gets or sets the face identifier. 47 | /// 48 | /// 49 | /// The face identifier. 50 | /// 51 | public Guid FaceId 52 | { 53 | get; set; 54 | } 55 | 56 | /// 57 | /// Gets or sets the user data. 58 | /// 59 | /// 60 | /// The user data. 61 | /// 62 | public string UserData 63 | { 64 | get; set; 65 | } 66 | 67 | #endregion Properties 68 | } 69 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/FaceRectangle.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | namespace Microsoft.ProjectOxford.Face.Contract 35 | { 36 | /// 37 | /// The face rectangle entity. 38 | /// 39 | public class FaceRectangle 40 | { 41 | #region Properties 42 | 43 | /// 44 | /// Gets or sets the width. 45 | /// 46 | /// 47 | /// The width. 48 | /// 49 | public int Width 50 | { 51 | get; set; 52 | } 53 | 54 | /// 55 | /// Gets or sets the height. 56 | /// 57 | /// 58 | /// The height. 59 | /// 60 | public int Height 61 | { 62 | get; set; 63 | } 64 | 65 | /// 66 | /// Gets or sets the left. 67 | /// 68 | /// 69 | /// The left of the face rectangle. 70 | /// 71 | public int Left 72 | { 73 | get; set; 74 | } 75 | 76 | /// 77 | /// Gets or sets the top. 78 | /// 79 | /// 80 | /// The top of the face rectangle. 81 | /// 82 | public int Top 83 | { 84 | get; set; 85 | } 86 | 87 | #endregion Properties 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/FacialHair.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | namespace Microsoft.ProjectOxford.Face.Contract 35 | { 36 | /// 37 | /// Represents length of moustache, beard and sideburn 38 | /// 39 | public class FacialHair 40 | { 41 | #region Properties 42 | 43 | /// 44 | /// Gets or sets the moustache value. Represents the length of moustache. 45 | /// 46 | /// 47 | /// The moustache value. 48 | /// 49 | public double Moustache 50 | { 51 | get; set; 52 | } 53 | 54 | /// 55 | /// Gets or sets the beard value. Represents the length of beard. 56 | /// 57 | /// 58 | /// The beard value. 59 | /// 60 | public double Beard 61 | { 62 | get; set; 63 | } 64 | 65 | /// 66 | /// Gets or sets the sideburns value. Represents the length of sideburns. 67 | /// 68 | /// 69 | /// The sideburns value. 70 | /// 71 | public double Sideburns 72 | { 73 | get; set; 74 | } 75 | 76 | #endregion Properties 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/FeatureCoordinate.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | namespace Microsoft.ProjectOxford.Face.Contract 35 | { 36 | /// 37 | /// The class for feature coordinate. 38 | /// 39 | public class FeatureCoordinate 40 | { 41 | #region Properties 42 | 43 | /// 44 | /// Gets or sets the x in pixel. 45 | /// 46 | /// 47 | /// The x of the feature coordinate. 48 | /// 49 | public double X 50 | { 51 | get; set; 52 | } 53 | 54 | /// 55 | /// Gets or sets the y in pixel. 56 | /// 57 | /// 58 | /// The y of the feature coordinate. 59 | /// 60 | public double Y 61 | { 62 | get; set; 63 | } 64 | 65 | #endregion Properties 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/GlassesTypes.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK/ 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 | namespace Microsoft.ProjectOxford.Face.Contract 35 | { 36 | /// 37 | /// Enumeration which represents the type of wearing glasses 38 | /// 39 | public enum Glasses 40 | { 41 | /// 42 | /// Indicates not wearing any glasses 43 | /// 44 | NoGlasses, 45 | 46 | /// 47 | /// Indicates wearing sunglasses 48 | /// 49 | Sunglasses, 50 | 51 | /// 52 | /// Indicates wearing reading glasses 53 | /// 54 | ReadingGlasses, 55 | 56 | /// 57 | /// Indicates wearing swimming goggles 58 | /// 59 | SwimmingGoggles 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/GroupResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 37 | namespace Microsoft.ProjectOxford.Face.Contract 38 | { 39 | /// 40 | /// The class for group result. 41 | /// 42 | public class GroupResult 43 | { 44 | #region Properties 45 | 46 | /// 47 | /// Gets or sets the groups. The groups are ranked by number of faces. 48 | /// 49 | /// 50 | /// The groups. 51 | /// 52 | public List Groups 53 | { 54 | get; set; 55 | } 56 | 57 | /// 58 | /// Gets or sets the messy group. Messy group contains all the faces which cannot find any similar faces from original faces. 59 | /// 60 | /// 61 | /// The messy group. 62 | /// 63 | public Guid[] MessyGroup 64 | { 65 | get; set; 66 | } 67 | 68 | #endregion Properties 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/HeadPose.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | namespace Microsoft.ProjectOxford.Face.Contract 35 | { 36 | /// 37 | /// The head pose entity. 38 | /// 39 | public class HeadPose 40 | { 41 | #region Properties 42 | 43 | /// 44 | /// Gets or sets the roll. 45 | /// 46 | /// 47 | /// The roll of the face pose. 48 | /// 49 | public double Roll 50 | { 51 | get; set; 52 | } 53 | 54 | /// 55 | /// Gets or sets the yaw. 56 | /// 57 | /// 58 | /// The yaw of the face pose. 59 | /// 60 | public double Yaw 61 | { 62 | get; set; 63 | } 64 | 65 | /// 66 | /// Gets or sets the pitch. 67 | /// 68 | /// 69 | /// The pitch of the face pose. 70 | /// 71 | public double Pitch 72 | { 73 | get; set; 74 | } 75 | 76 | #endregion Properties 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/IdentifyResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | /// 39 | /// The identification result. 40 | /// 41 | public class IdentifyResult 42 | { 43 | #region Properties 44 | 45 | /// 46 | /// Gets or sets the face identifier. 47 | /// 48 | /// 49 | /// The face identifier. 50 | /// 51 | public Guid FaceId 52 | { 53 | get; set; 54 | } 55 | 56 | /// 57 | /// Gets or sets the candidates. 58 | /// 59 | /// 60 | /// The candidates. 61 | /// 62 | public Candidate[] Candidates 63 | { 64 | get; set; 65 | } 66 | 67 | #endregion Properties 68 | } 69 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/Person.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | /// 39 | /// The person entity. 40 | /// 41 | public class Person 42 | { 43 | #region Properties 44 | 45 | /// 46 | /// Gets or sets the person identifier. 47 | /// 48 | /// 49 | /// The person identifier. 50 | /// 51 | public Guid PersonId 52 | { 53 | get; set; 54 | } 55 | 56 | /// 57 | /// Gets or sets the persisted face ids. 58 | /// 59 | /// 60 | /// The persisted face ids. 61 | /// 62 | public Guid[] PersistedFaceIds 63 | { 64 | get; set; 65 | } 66 | 67 | /// 68 | /// Gets or sets the name. 69 | /// 70 | /// 71 | /// The name of the person. 72 | /// 73 | public string Name 74 | { 75 | get; set; 76 | } 77 | 78 | /// 79 | /// Gets or sets the profile. 80 | /// 81 | /// 82 | /// The profile. 83 | /// 84 | public string UserData 85 | { 86 | get; set; 87 | } 88 | 89 | #endregion Properties 90 | } 91 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/PersonFace.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | /// 39 | /// The person face entity. 40 | /// 41 | public class PersonFace 42 | { 43 | #region Properties 44 | 45 | /// 46 | /// Gets or sets the persisted face identifier. 47 | /// 48 | /// 49 | /// The persisted face identifier. 50 | /// 51 | public Guid PersistedFaceId 52 | { 53 | get; 54 | set; 55 | } 56 | 57 | /// 58 | /// Gets or sets the user data. 59 | /// 60 | /// 61 | /// The user data. 62 | /// 63 | public string UserData 64 | { 65 | get; set; 66 | } 67 | 68 | #endregion Properties 69 | } 70 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/PersonGroup.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | namespace Microsoft.ProjectOxford.Face.Contract 35 | { 36 | /// 37 | /// The person group entity. 38 | /// 39 | public class PersonGroup 40 | { 41 | #region Properties 42 | 43 | /// 44 | /// Gets or sets the person group identifier. 45 | /// 46 | /// 47 | /// The person group identifier. 48 | /// 49 | public string PersonGroupId 50 | { 51 | get; set; 52 | } 53 | 54 | /// 55 | /// Gets or sets the name. 56 | /// 57 | /// 58 | /// The name of the person group. 59 | /// 60 | public string Name 61 | { 62 | get; set; 63 | } 64 | 65 | /// 66 | /// Gets or sets the user data. 67 | /// 68 | /// 69 | /// The user data. 70 | /// 71 | public string UserData 72 | { 73 | get; set; 74 | } 75 | 76 | #endregion Properties 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/SimilarFace.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | /// 39 | /// The class for similar face. 40 | /// 41 | public class SimilarFace 42 | { 43 | #region Properties 44 | 45 | /// 46 | /// Gets or sets the face identifier. 47 | /// 48 | /// 49 | /// The face identifier. 50 | /// 51 | public Guid FaceId 52 | { 53 | get; set; 54 | } 55 | 56 | /// 57 | /// Gets or sets the confidence. 58 | /// 59 | /// 60 | /// The confidence. 61 | /// 62 | public double Confidence 63 | { 64 | get; set; 65 | } 66 | 67 | #endregion Properties 68 | } 69 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/SimilarPersistedFace.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | /// 39 | /// The class for similar persisted face. 40 | /// 41 | public class SimilarPersistedFace 42 | { 43 | #region Properties 44 | 45 | /// 46 | /// Gets or sets the persisted face identifier. 47 | /// 48 | /// 49 | /// The persisted face identifier. 50 | /// 51 | public Guid PersistedFaceId 52 | { 53 | get; set; 54 | } 55 | 56 | /// 57 | /// Gets or sets the confidence value. 58 | /// 59 | /// 60 | /// The confidence value. 61 | /// 62 | public double Confidence 63 | { 64 | get; set; 65 | } 66 | 67 | #endregion Properties 68 | } 69 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/TrainingStatus.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | 36 | namespace Microsoft.ProjectOxford.Face.Contract 37 | { 38 | #region Enumerations 39 | 40 | /// 41 | /// Enumeration represents status of training 42 | /// 43 | public enum Status 44 | { 45 | /// 46 | /// Training succeeded 47 | /// 48 | Succeeded, 49 | 50 | /// 51 | /// Training failed 52 | /// 53 | Failed, 54 | 55 | /// 56 | /// Training still in progress 57 | /// 58 | Running 59 | } 60 | 61 | #endregion Enumerations 62 | 63 | /// 64 | /// The training status entity. 65 | /// 66 | public class TrainingStatus 67 | { 68 | #region Properties 69 | 70 | /// 71 | /// Gets or sets the status. 72 | /// 73 | /// 74 | /// The status. 75 | /// 76 | public Status Status 77 | { 78 | get; set; 79 | } 80 | 81 | /// 82 | /// Gets or sets the create time. 83 | /// 84 | /// 85 | /// The create time. 86 | /// 87 | public DateTime CreatedDateTime 88 | { 89 | get; set; 90 | } 91 | 92 | /// 93 | /// Gets or sets the last action time. 94 | /// 95 | /// 96 | /// The last action time. 97 | /// 98 | public DateTime LastActionDateTime 99 | { 100 | get; set; 101 | } 102 | 103 | /// 104 | /// Gets or sets the message. 105 | /// 106 | /// 107 | /// The message. 108 | /// 109 | public string Message 110 | { 111 | get; set; 112 | } 113 | 114 | #endregion Properties 115 | } 116 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Contract/VerifyResult.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | namespace Microsoft.ProjectOxford.Face.Contract 35 | { 36 | /// 37 | /// The verify result entity. 38 | /// 39 | public class VerifyResult 40 | { 41 | #region Properties 42 | 43 | /// 44 | /// Gets or sets a value indicating whether this instance is same. 45 | /// 46 | /// 47 | /// true if this instance is same; otherwise, false. 48 | /// 49 | public bool IsIdentical 50 | { 51 | get; set; 52 | } 53 | 54 | /// 55 | /// Gets or sets the confidence. 56 | /// 57 | /// 58 | /// The confidence. 59 | /// 60 | public double Confidence 61 | { 62 | get; set; 63 | } 64 | 65 | #endregion Properties 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/FaceAPIException.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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.Net; 36 | 37 | namespace Microsoft.ProjectOxford.Face 38 | { 39 | /// 40 | /// Represents client error with detailed error message and error code 41 | /// 42 | public class FaceAPIException : Exception 43 | { 44 | #region Constructors 45 | 46 | /// 47 | /// Initializes a new instance of the class 48 | /// 49 | public FaceAPIException() 50 | { 51 | } 52 | 53 | /// 54 | /// Initializes a new instance of the class 55 | /// 56 | /// Code represents the error category 57 | /// Message represents the detailed error description 58 | /// Http status code 59 | public FaceAPIException(string errorCode, string errorMessage, HttpStatusCode statusCode) 60 | { 61 | ErrorCode = errorCode; 62 | ErrorMessage = errorMessage; 63 | HttpStatus = statusCode; 64 | } 65 | 66 | #endregion Constructors 67 | 68 | #region Properties 69 | 70 | /// 71 | /// Gets or sets the error code 72 | /// 73 | public string ErrorCode 74 | { 75 | get; set; 76 | } 77 | 78 | /// 79 | /// Gets or sets the error message 80 | /// 81 | public string ErrorMessage 82 | { 83 | get; set; 84 | } 85 | 86 | /// 87 | /// Gets or sets http status of http response. 88 | /// 89 | /// 90 | /// The HTTP status. 91 | /// 92 | public HttpStatusCode HttpStatus 93 | { 94 | get; set; 95 | } 96 | 97 | #endregion Properties 98 | } 99 | } -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/FaceClientSDK.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Microsoft.ProjectOxford.Face 5 | Microsoft Project Oxford Face API Client Library 6 | $version$ 7 | Microsoft 8 | Microsoft 9 | https://github.com/Microsoft/ProjectOxford-ClientSDK/blob/master/LICENSE.md 10 | https://github.com/Microsoft/ProjectOxford-ClientSDK/tree/master/Face 11 | https://www.projectoxford.ai/images/bright/face/FaceAPI-Main.png 12 | true 13 | Microsoft Project Oxford Face API Client Library 14 | Use Face API Client Library to enrich your apps with Microsoft's state-of-the-art cloud-based face algorithms. 15 | Project Oxford Face API V1.0 Client SDK 16 | Copyright 2015 17 | Face, Oxford, ProjectOxford 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Microsoft.ProjectOxford.Face.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 11.0 6 | Debug 7 | AnyCPU 8 | {25D58BA5-660F-407B-803C-22B4547C09DC} 9 | Library 10 | Properties 11 | Microsoft.ProjectOxford.Face 12 | Microsoft.ProjectOxford.Face 13 | en-US 14 | 512 15 | {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 16 | Profile111 17 | v4.5 18 | SAK 19 | SAK 20 | SAK 21 | SAK 22 | 23 | 24 | true 25 | full 26 | false 27 | bin\Debug\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | 32 | 33 | pdbonly 34 | true 35 | bin\Release\ 36 | TRACE 37 | prompt 38 | 4 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | ..\packages\Newtonsoft.Json.10.0.2\lib\portable-net45+win8+wpa81+wp8\Newtonsoft.Json.dll 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Microsoft.ProjectOxford.Face.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.23107.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.ProjectOxford.Face", "Microsoft.ProjectOxford.Face.csproj", "{25D58BA5-660F-407B-803C-22B4547C09DC}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {25D58BA5-660F-407B-803C-22B4547C09DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {25D58BA5-660F-407B-803C-22B4547C09DC}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {25D58BA5-660F-407B-803C-22B4547C09DC}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {25D58BA5-660F-407B-803C-22B4547C09DC}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (c) Microsoft. All rights reserved. 3 | // Licensed under the MIT license. 4 | // 5 | // Microsoft Cognitive Services (formerly Project Oxford): https://www.microsoft.com/cognitive-services 6 | // 7 | // Microsoft Cognitive Services (formerly Project Oxford) GitHub: 8 | // https://github.com/Microsoft/ProjectOxford-ClientSDK 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 | using System.Reflection; 34 | using System.Resources; 35 | 36 | [assembly: AssemblyTitle("Microsoft.ProjectOxford.Face")] 37 | [assembly: AssemblyDescription("Microsoft.ProjectOxford.Face")] 38 | [assembly: AssemblyCompany("Microsoft")] 39 | [assembly: AssemblyProduct("Microsoft ProjectOxford")] 40 | [assembly: AssemblyCopyright("Copyright © 2015 Microsoft")] 41 | [assembly: AssemblyTrademark("Microsoft")] 42 | [assembly: NeutralResourcesLanguage("en")] 43 | 44 | [assembly: AssemblyVersion("1.1.0.0")] 45 | [assembly: AssemblyFileVersion("1.1.0.0")] -------------------------------------------------------------------------------- /LiveCam/Microsoft.ProjectOxford.Face/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /LiveCam/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 | -------------------------------------------------------------------------------- /LiveCam/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.Common.Contract; 36 | using Microsoft.ProjectOxford.Face.Contract; 37 | using System; 38 | using System.Collections.Generic; 39 | using System.Linq; 40 | 41 | namespace ServiceHelpers 42 | { 43 | public class CoreUtil 44 | { 45 | public static uint MinDetectableFaceCoveragePercentage = 0; 46 | 47 | public static bool IsFaceBigEnoughForDetection(int faceHeight, int imageHeight) 48 | { 49 | if (imageHeight == 0) 50 | { 51 | // sometimes we don't know the size of the image, so we assume the face is big enough 52 | return true; 53 | } 54 | 55 | double faceHeightPercentage = 100 * ((double)faceHeight / imageHeight); 56 | 57 | return faceHeightPercentage >= MinDetectableFaceCoveragePercentage; 58 | } 59 | 60 | public static Emotion FindFaceClosestToRegion(IEnumerable emotion, FaceRectangle region) 61 | { 62 | return emotion?.Where(e => CoreUtil.AreFacesPotentiallyTheSame(e.FaceRectangle, region)) 63 | .OrderBy(e => Math.Abs(region.Left - e.FaceRectangle.Left) + Math.Abs(region.Top - e.FaceRectangle.Top)).FirstOrDefault(); 64 | } 65 | 66 | public static bool AreFacesPotentiallyTheSame(Rectangle face1, FaceRectangle face2) 67 | { 68 | return AreFacesPotentiallyTheSame((int)face1.Left, (int)face1.Top, (int)face1.Width, (int)face1.Height, face2.Left, face2.Top, face2.Width, face2.Height); 69 | } 70 | 71 | public static bool AreFacesPotentiallyTheSame(int face1X, int face1Y, int face1Width, int face1Height, 72 | int face2X, int face2Y, int face2Width, int face2Height) 73 | { 74 | double distanceThresholdFactor = 1; 75 | double sizeThresholdFactor = 0.5; 76 | 77 | // See if faces are close enough from each other to be considered the "same" 78 | if (Math.Abs(face1X - face2X) <= face1Width * distanceThresholdFactor && 79 | Math.Abs(face1Y - face2Y) <= face1Height * distanceThresholdFactor) 80 | { 81 | // See if faces are shaped similarly enough to be considered the "same" 82 | if (Math.Abs(face1Width - face2Width) <= face1Width * sizeThresholdFactor && 83 | Math.Abs(face1Height - face2Height) <= face1Height * sizeThresholdFactor) 84 | { 85 | return true; 86 | } 87 | } 88 | 89 | return false; 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /LiveCam/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.Common.Contract; 36 | using Microsoft.ProjectOxford.Emotion; 37 | using System; 38 | using System.Collections.Generic; 39 | using System.IO; 40 | using System.Threading.Tasks; 41 | 42 | namespace ServiceHelpers 43 | { 44 | public class EmotionData 45 | { 46 | public string EmotionName { get; set; } 47 | public float EmotionScore { get; set; } 48 | } 49 | 50 | public static class EmotionServiceHelper 51 | { 52 | public static int RetryCountOnQuotaLimitError = 6; 53 | public static int RetryDelayOnQuotaLimitError = 500; 54 | 55 | private static EmotionServiceClient emotionClient { get; set; } 56 | 57 | static EmotionServiceHelper() 58 | { 59 | InitializeEmotionService(); 60 | } 61 | 62 | public static Action Throttled; 63 | 64 | private static string apiKey; 65 | public static string ApiKey 66 | { 67 | get { return apiKey; } 68 | set 69 | { 70 | var changed = apiKey != value; 71 | apiKey = value; 72 | if (changed) 73 | { 74 | InitializeEmotionService(); 75 | } 76 | } 77 | } 78 | 79 | private static void InitializeEmotionService() 80 | { 81 | emotionClient = new EmotionServiceClient(apiKey); 82 | } 83 | 84 | private static async Task RunTaskWithAutoRetryOnQuotaLimitExceededError(Func> action) 85 | { 86 | int retriesLeft = FaceServiceHelper.RetryCountOnQuotaLimitError; 87 | int delay = FaceServiceHelper.RetryDelayOnQuotaLimitError; 88 | 89 | TResponse response = default(TResponse); 90 | 91 | while (true) 92 | { 93 | try 94 | { 95 | response = await action(); 96 | break; 97 | } 98 | catch (ClientException exception) when (exception.HttpStatus == (System.Net.HttpStatusCode)429 && retriesLeft > 0) 99 | { 100 | ErrorTrackingHelper.TrackException(exception, "Emotion API throttling error"); 101 | if (retriesLeft == 1 && Throttled != null) 102 | { 103 | Throttled(); 104 | } 105 | 106 | await Task.Delay(delay); 107 | retriesLeft--; 108 | delay *= 2; 109 | continue; 110 | } 111 | } 112 | 113 | return response; 114 | } 115 | 116 | private static async Task RunTaskWithAutoRetryOnQuotaLimitExceededError(Func action) 117 | { 118 | await RunTaskWithAutoRetryOnQuotaLimitExceededError(async () => { await action(); return null; }); 119 | } 120 | 121 | public static async Task RecognizeAsync(Func> imageStreamCallback) 122 | { 123 | return await RunTaskWithAutoRetryOnQuotaLimitExceededError(async () => await emotionClient.RecognizeAsync(await imageStreamCallback())); 124 | } 125 | 126 | public static async Task RecognizeAsync(string url) 127 | { 128 | return await RunTaskWithAutoRetryOnQuotaLimitExceededError(async () => await emotionClient.RecognizeAsync(url)); 129 | } 130 | 131 | public static IEnumerable ScoresToEmotionData(EmotionScores scores) 132 | { 133 | List result = new List(); 134 | result.Add(new EmotionData { EmotionName = "Anger", EmotionScore = scores.Anger }); 135 | result.Add(new EmotionData { EmotionName = "Contempt", EmotionScore = scores.Contempt }); 136 | result.Add(new EmotionData { EmotionName = "Disgust", EmotionScore = scores.Disgust }); 137 | result.Add(new EmotionData { EmotionName = "Fear", EmotionScore = scores.Fear }); 138 | result.Add(new EmotionData { EmotionName = "Happiness", EmotionScore = scores.Happiness }); 139 | result.Add(new EmotionData { EmotionName = "Neutral", EmotionScore = scores.Neutral }); 140 | result.Add(new EmotionData { EmotionName = "Sadness", EmotionScore = scores.Sadness }); 141 | result.Add(new EmotionData { EmotionName = "Surprise", EmotionScore = scores.Surprise }); 142 | 143 | return result; 144 | } 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /LiveCam/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 | -------------------------------------------------------------------------------- /LiveCam/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(Func> imageStreamCallback, Guid faceId, Face face) 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 | double maxAngle = 30; 145 | if (face.FaceAttributes.HeadPose != null && 146 | (Math.Abs(face.FaceAttributes.HeadPose.Yaw) > maxAngle || 147 | Math.Abs(face.FaceAttributes.HeadPose.Pitch) > maxAngle || 148 | Math.Abs(face.FaceAttributes.HeadPose.Roll) > maxAngle)) 149 | { 150 | // This isn't a good frontal shot, so let's not use it as the primary example face for this person 151 | return null; 152 | } 153 | 154 | if (!faceLists.Any()) 155 | { 156 | // We don't have any FaceLists yet. Create one 157 | string newFaceListId = Guid.NewGuid().ToString(); 158 | await FaceServiceHelper.CreateFaceListAsync(newFaceListId, "ManagedFaceList", FaceListsUserDataFilter); 159 | 160 | faceLists.Add(newFaceListId, new FaceListInfo { FaceListId = newFaceListId, LastMatchTimestamp = DateTime.Now }); 161 | } 162 | 163 | AddPersistedFaceResult addResult = null; 164 | bool failedToAddToNonFullList = false; 165 | foreach (var faceList in faceLists) 166 | { 167 | if (faceList.Value.IsFull) 168 | { 169 | continue; 170 | } 171 | 172 | try 173 | { 174 | addResult = await FaceServiceHelper.AddFaceToFaceListAsync(faceList.Key, imageStreamCallback, face.FaceRectangle); 175 | break; 176 | } 177 | catch (Exception ex) 178 | { 179 | if (ex is FaceAPIException && ((FaceAPIException)ex).ErrorCode == "403") 180 | { 181 | // FaceList is full. Continue so we can try again with the next FaceList 182 | faceList.Value.IsFull = true; 183 | continue; 184 | } 185 | else 186 | { 187 | failedToAddToNonFullList = true; 188 | break; 189 | } 190 | } 191 | } 192 | 193 | if (addResult == null && !failedToAddToNonFullList) 194 | { 195 | // We were not able to add the face to an existing list because they were all full. 196 | 197 | // 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), 198 | // let's delete an old list, create a new one and add the new face to it. 199 | 200 | if (faceLists.Count == 64) 201 | { 202 | // delete oldest face list 203 | var oldestFaceList = faceLists.OrderBy(fl => fl.Value.LastMatchTimestamp).FirstOrDefault(); 204 | faceLists.Remove(oldestFaceList.Key); 205 | await FaceServiceHelper.DeleteFaceListAsync(oldestFaceList.Key); 206 | } 207 | 208 | // create new list 209 | string newFaceListId = Guid.NewGuid().ToString(); 210 | await FaceServiceHelper.CreateFaceListAsync(newFaceListId, "ManagedFaceList", FaceListsUserDataFilter); 211 | faceLists.Add(newFaceListId, new FaceListInfo { FaceListId = newFaceListId, LastMatchTimestamp = DateTime.Now }); 212 | 213 | // Add face to new list 214 | addResult = await FaceServiceHelper.AddFaceToFaceListAsync(newFaceListId, imageStreamCallback, face.FaceRectangle); 215 | } 216 | 217 | if (addResult != null) 218 | { 219 | bestMatch = new Tuple(new SimilarPersistedFace { Confidence = 1, PersistedFaceId = addResult.PersistedFaceId }, null); 220 | } 221 | } 222 | 223 | return bestMatch?.Item1; 224 | } 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /LiveCam/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 | -------------------------------------------------------------------------------- /LiveCam/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.324\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Common.dll 57 | True 58 | 59 | 60 | ..\packages\Microsoft.ProjectOxford.Emotion.1.0.336\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Emotion.dll 61 | True 62 | 63 | 64 | ..\packages\Microsoft.ProjectOxford.Vision.1.0.372\lib\portable-net45+win+wpa81+wp80+MonoAndroid10+xamarinios10+MonoTouch10\Microsoft.ProjectOxford.Vision.dll 65 | True 66 | 67 | 68 | ..\packages\Newtonsoft.Json.10.0.2\lib\portable-net45+win8+wpa81+wp8\Newtonsoft.Json.dll 69 | 70 | 71 | ..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net45+win8\System.Net.Http.Extensions.dll 72 | True 73 | 74 | 75 | ..\packages\Microsoft.Net.Http.2.2.29\lib\portable-net45+win8\System.Net.Http.Primitives.dll 76 | True 77 | 78 | 79 | 80 | 81 | 82 | Designer 83 | 84 | 85 | 86 | 87 | {25D58BA5-660F-407B-803C-22B4547C09DC} 88 | Microsoft.ProjectOxford.Face 89 | 90 | 91 | 92 | 93 | 94 | 95 | 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}. 96 | 97 | 98 | 99 | 106 | -------------------------------------------------------------------------------- /LiveCam/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 | -------------------------------------------------------------------------------- /LiveCam/ServiceHelpers/VisionServiceHelper.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.Vision; 35 | using Microsoft.ProjectOxford.Vision.Contract; 36 | using System; 37 | using System.Collections.Generic; 38 | using System.IO; 39 | using System.Threading.Tasks; 40 | 41 | namespace ServiceHelpers 42 | { 43 | public static class VisionServiceHelper 44 | { 45 | public static int RetryCountOnQuotaLimitError = 6; 46 | public static int RetryDelayOnQuotaLimitError = 500; 47 | 48 | private static VisionServiceClient visionClient { get; set; } 49 | 50 | static VisionServiceHelper() 51 | { 52 | InitializeEmotionService(); 53 | } 54 | 55 | public static Action Throttled; 56 | 57 | private static string apiKey; 58 | public static string ApiKey 59 | { 60 | get 61 | { 62 | return apiKey; 63 | } 64 | 65 | set 66 | { 67 | var changed = apiKey != value; 68 | apiKey = value; 69 | if (changed) 70 | { 71 | InitializeEmotionService(); 72 | } 73 | } 74 | } 75 | 76 | private static void InitializeEmotionService() 77 | { 78 | visionClient = new VisionServiceClient(apiKey); 79 | } 80 | 81 | private static async Task RunTaskWithAutoRetryOnQuotaLimitExceededError(Func> action) 82 | { 83 | int retriesLeft = FaceServiceHelper.RetryCountOnQuotaLimitError; 84 | int delay = FaceServiceHelper.RetryDelayOnQuotaLimitError; 85 | 86 | TResponse response = default(TResponse); 87 | 88 | while (true) 89 | { 90 | try 91 | { 92 | response = await action(); 93 | break; 94 | } 95 | catch (Microsoft.ProjectOxford.Vision.ClientException exception) when (exception.HttpStatus == (System.Net.HttpStatusCode)429 && retriesLeft > 0) 96 | { 97 | if (retriesLeft == 1 && Throttled != null) 98 | { 99 | Throttled(); 100 | } 101 | 102 | await Task.Delay(delay); 103 | retriesLeft--; 104 | delay *= 2; 105 | continue; 106 | } 107 | } 108 | 109 | return response; 110 | } 111 | 112 | private static async Task RunTaskWithAutoRetryOnQuotaLimitExceededError(Func action) 113 | { 114 | await RunTaskWithAutoRetryOnQuotaLimitExceededError(async () => { await action(); return null; } ); 115 | } 116 | 117 | public static async Task DescribeAsync(Func> imageStreamCallback) 118 | { 119 | return await RunTaskWithAutoRetryOnQuotaLimitExceededError(async () => await visionClient.DescribeAsync(await imageStreamCallback())); 120 | } 121 | 122 | public static async Task AnalyzeImageAsync(string imageUrl, IEnumerable visualFeatures = null, IEnumerable details = null) 123 | { 124 | return await RunTaskWithAutoRetryOnQuotaLimitExceededError(() => visionClient.AnalyzeImageAsync(imageUrl, visualFeatures, details)); 125 | } 126 | 127 | public static async Task AnalyzeImageAsync(Func> imageStreamCallback, IEnumerable visualFeatures = null, IEnumerable details = null) 128 | { 129 | return await RunTaskWithAutoRetryOnQuotaLimitExceededError(async () => await visionClient.AnalyzeImageAsync(await imageStreamCallback(), visualFeatures, details )); 130 | } 131 | 132 | public static async Task DescribeAsync(string imageUrl) 133 | { 134 | return await RunTaskWithAutoRetryOnQuotaLimitExceededError(() => visionClient.DescribeAsync(imageUrl)); 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /LiveCam/ServiceHelpers/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /LiveCam/ServiceHelpers/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Face Detection & Recognition 2 | 3 | * Android sample uses Google's Mobile Vision APIs for face detection and Microsoft Cognitive Services for Recognition. 4 | * iOS samples use CIDetector and CIFeature for Face Detection and Microsoft Cognitive Services for Recognitio 5 | 6 | Microsoft Cognitive Services Client APIs and Helpers were reused from this [sample](https://github.com/Microsoft/Cognitive-Samples-IntelligentKiosk) 7 | 8 | > Note: The demo samples use Face Registration in the load method of the app. Do not use that in your production. The best place to use them is in the user registration page. 9 | --------------------------------------------------------------------------------