private async Task LoadDatabaseFaces() { //await Task.Run(() => // { using (var db = new Facial_Recognition_Library.Data.LiveEduFaceModel()) { loDatabaseFaces = await db.MyFaces.ToListAsync(); } // }).ContinueWith((task, o) => // { SyncContext.Post(new SendOrPostCallback(o => { UpdateMyFacesBindingSource(); }), null); // }, null, TaskScheduler.FromCurrentSynchronizationContext()); }
private async Task LoadDatabasePersonGroups() { //await Task.Run(async () => //{ using (var db = new Facial_Recognition_Library.Data.LiveEduFaceModel()) { loDabasePersonGroups = await db.MyPersonGroups.ToListAsync(); } //}).ContinueWith((task, o) => //{ SyncContext.Post(new SendOrPostCallback(o => { DatabasePersonGroupBindingSource.DataSource = loDabasePersonGroups; DatabasePersonGroupBindingSource.ResetBindings(false); }), null); //}, null, TaskScheduler.FromCurrentSynchronizationContext()); }
/// <summary> /// Process the image using the CognitiveServiceAPI Class: (Direct HTTP client interface manamgent /// </summary> /// <param name="MyCurrentImage"></param> /// <param name="saveLocal"></param> private void ProcessImage(Image MyCurrentImage, bool saveLocal = false) { if (saveLocal) { MyCurrentImage.Save($@"W:\Example Pictures\MyImage{DateTime.Now.ToFileTime()}.png", ImageFormat.Png); } //ImageType.Text = Enum.GetName(typeof(System.Drawing.Imaging.ImageFormat), MyCurrentImage.RawFormat); using (MemoryStream ms = new MemoryStream()) { MyCurrentImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png); Facial_Recognition_Library.API.CognitiveServiceAPI serviceApi = new CognitiveServiceAPI(); //Settings serviceApi.ThrowErrorToParent = true; //There are several ways of doing this, and all have direct relationship to how much control you want to have. //Thus, this is the simplest and most convient method where in you are given just what you need to complete the task. //using (HttpClient hcClient = new HttpClient()) HttpClient hcClient = new HttpClient(); List <FaceDetectFaceResult> FaceDetectResult = new List <FaceDetectFaceResult>(); try { FaceDetectResult = serviceApi.GetFaceDetectResult(ms, ref hcClient); } catch (Exception e) { MessageBox.Show(e.Message); } try { if (FaceDetectResult?.Count > 0) { foreach (var face in FaceDetectResult) { //Do Something MyFace newface = new MyFace { FaceID = Guid.Parse(face.FaceId), FaceAttributes = face.getJsonFaceAttibutes(), FaceLandmarks = face.getJsonFaceLandmarks(), FaceRectangle = face.getJsonFaceRectangle(), ImageBytes = ms.ToArray() }; using (var db = new Facial_Recognition_Library.Data.LiveEduFaceModel()) { db.MyFaces.Add(newface); db.SaveChanges(); foreach (var faceItem in db.MyFaces) { System.Diagnostics.Debug.WriteLine($"{faceItem.FaceID.ToString()} - {faceItem.FaceRectangle}"); } } } } } catch (Exception e) { //MessageBox.Show(e.Message); //throw e; } } }