public void SendImageToService_Test() { Facial_Recognition_Library.API.CognitiveServiceAPI capi = new Facial_Recognition_Library.API.CognitiveServiceAPI(); var client = new HttpClient(); var rtn = capi.RequestFaceDetect(@"W:\Example Pictures\MyImage.png", ref client); Assert.IsTrue(!string.IsNullOrWhiteSpace(rtn)); var data = FaceApiFaceDetectResult.FromJson(rtn).First(); Facial_Recognition_Library.Data.LiveEduFaceModel fm = new LiveEduFaceModel(); MyFace face = new MyFace { FaceID = Guid.Parse(data.FaceId), FaceAttributes = data.getJsonFaceAttibutes(), FaceRectangle = data.getJsonFaceRectangle(), //BitmapImage = Image.FromFile(@"W:\Example Pictures\MyImage.png") ImageBytes = Facial_Recognition_Library.API.CognitiveServiceAPI.GetImageAsByteArray(@"W:\Example Pictures\MyImage.png") }; using (var db = new LiveEduFaceModel()) { db.MyFaces.Add(face); db.SaveChanges(); foreach (var faceItem in db.MyFaces) { System.Diagnostics.Debug.WriteLine($"{faceItem.FaceID.ToString()} - {faceItem.FaceRectangle}"); } } }
private async void createNewFaceListToolStripMenuItem_Click(object sender, EventArgs e) { //TODO: Move this to the libary : createNewFaceListToolStripMenuItem_Click Guid FaceListID = Guid.Empty; using (var db = new LiveEduFaceModel()) { var myfaceList = new MyFaceList(); //db.MyFaceLists.Create(); db.MyFaceLists.Add(myfaceList); db.SaveChanges(); FaceListID = myfaceList.ID; frmCreateNewFaceList frmCreateNewFaceList = new frmCreateNewFaceList(FaceListID); bool Successful = OpenfrmCreateNewFaceList(frmCreateNewFaceList); if (Successful) { myfaceList.FaceListId = frmCreateNewFaceList.FaceListID; myfaceList.Name = frmCreateNewFaceList.FaceListName; myfaceList.UserData = frmCreateNewFaceList.FaceListUserData; if (myfaceList.UserData != FaceListID.ToString()) { //Throw an error?? } } else { //Clean up the DB due to Error or cancelation db.MyFaceLists.Remove(myfaceList); } db.SaveChanges(); } await LoadDatabaseFaceLists(); await LoadAPIFaceList(); }
/// <summary> /// Add person group to database /// </summary> /// <param name="db"></param> /// <param name="PersonGroup"></param> /// <returns></returns> /// <remarks>Add's "Last Action" to object to keep track of adjustments</remarks> public static bool AddPersonGroup(LiveEduFaceModel db, ref MyPersonGroup PersonGroup) { PersonGroup.LastAction = "Add"; PersonGroup.LastActionDateTime = DateTime.Now; PersonGroup = db.MyPersonGroups.Add(PersonGroup); return(true); }
public static bool AddPerson(LiveEduFaceModel db, ref MyPerson person) { person.LastAction = "ADD"; person.LastActionDateTime = DateTime.Now; //Here is where the failure happens. throw new Exception("test"); person = db.MyPersons.Add(person); return(true); }
public static MyFace GetMyFaceByID(Guid MyFaceSystemID) { MyFace rtnFace = null; using (var db = new LiveEduFaceModel()) { rtnFace = db.MyFaces.Single(x => x.ID == MyFaceSystemID); } return(rtnFace); }
/// <summary> /// Event handlers for the Data Grid View "Face Lists In DB" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="column"></param> /// <returns></returns> public static DataGridViewsProcessResult DgvFaceListDb(ref object sender, DataGridViewCellEventArgs e, DataGridViewColumn column) { DataGridViewsProcessResult methodResult = new DataGridViewsProcessResult(); if (sender is DataGridView dgvFaceListInDB) { if (e.RowIndex < 0) { return(null); } //NAME: Delete Face List if (e.ColumnIndex == dgvFaceListInDB.Columns[column.Name]?.Index) { //NAME: DELETE FACE LIST //TODO: The Cell Reference needs to be exact so that users can move the Columns. Guid faceListDbid = (Guid)dgvFaceListInDB[0, e.RowIndex].Value; var concent = MessageBox.Show($@"Are you sure you want to delete {faceListDbid.ToString()} from the DB and API?", $@"Remove Face List", MessageBoxButtons.OKCancel); if (concent == DialogResult.OK) { string faceListId = ""; using (var db = new LiveEduFaceModel()) { var myFaceList = db.MyFaceLists.Single(x => x.ID == faceListDbid); faceListId = myFaceList.FaceListId; db.MyFaceLists.Remove(myFaceList); db.SaveChanges(); } bool Success = ProjectOxfordAPI.DeleteFaceListByFaceListID(faceListId).Result; if (Success) { MessageBox.Show($@"Item Removed: Refreshing Data"); //LoadAPIFaceList(); } } else { } } else if (e.ColumnIndex == dgvFaceListInDB.Columns[column.Name]?.Index) { //SHOW FACE LIST DETAILS } else { } } return(methodResult); }
public static bool DeletePersonById(LiveEduFaceModel db, string personGroupId, out Guid uuidPersonId) { throw new NotImplementedException(); }
public static bool DeletePersonGroupById(LiveEduFaceModel db, string personGroupId) { db.MyPersonGroups.Remove(db.MyPersonGroups.Single(pg => pg.IDApi == personGroupId)); return(true); }
/// <summary> /// Event handlers for the Data Grid View "Images In DB" /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="Column"></param> /// <param name="DataGridViewColumns"></param> /// <exception cref="Facial_Recognition_Library.Controls.DataGridViewsFaceDetectException">This is thrown with an image contains more than one face. We cannot register a face when more than one is within the image.</exception> /// <returns></returns> public static DataGridViewsProcessResult DgvImagesInDbAsync(ref object sender, DataGridViewCellEventArgs e, DataGridViewColumn Column, params DataGridViewColumn[] DataGridViewColumns) { throw new NotImplementedException("The ASYNC methods have not been compeleted. Please review and remove this exception before use."); DataGridViewsProcessResult methodResult = new DataGridViewsProcessResult(); DataGridView dgvImagesInDb = (DataGridView)sender; if (Column != null) { DataGridViewColumn ResendToDetect = Column; DataGridViewColumn dgvBtnAddToCurrentFaceList = Column; DataGridViewColumn SystemIDdgvtxtColumn = null; DataGridViewColumn faceRectangleDataGridViewTextBoxColumn = null; DataGridViewColumn imageBytesDataGridViewImageColumn = null; bool GridViewColumnsInitialized = false; if (DataGridViewColumns?.Length > 0) { try { SystemIDdgvtxtColumn = DataGridViewColumns.First(dgvc => dgvc.Name == "SystemIDdgvtxtColumn"); faceRectangleDataGridViewTextBoxColumn = DataGridViewColumns.First(dgvc => dgvc.Name == "faceRectangleDataGridViewTextBoxColumn"); imageBytesDataGridViewImageColumn = DataGridViewColumns.First(dgvc => dgvc.Name == "imageBytesDataGridViewImageColumn"); GridViewColumnsInitialized = true; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); System.Diagnostics.Debug.WriteLine($"Failed to retrieve the columns for data retrieval."); methodResult.Success = false; } } else { SystemIDdgvtxtColumn = dgvImagesInDb.Columns.OfType <DataGridViewColumn>().First(dgvc => dgvc.Name == "SystemIdDataGridViewTextBoxColumn"); faceRectangleDataGridViewTextBoxColumn = dgvImagesInDb.Columns.OfType <DataGridViewColumn>().First(dgvc => dgvc.Name == "rectangleDataGridViewTextBoxColumn"); imageBytesDataGridViewImageColumn = dgvImagesInDb.Columns.OfType <DataGridViewColumn>().First(dgvc => dgvc.Name == "dataGridViewImageColumn2"); } //Providing this style of Index lookup allows the Columns to be moved around. so the function stays the same if (e.ColumnIndex == dgvImagesInDb.Columns[ResendToDetect.Name].Index) { System.Diagnostics.Debug.WriteLine($"Row index is {e.RowIndex}"); Guid FaceSystemID = new Guid(dgvImagesInDb[SystemIDdgvtxtColumn.Index, e.RowIndex].Value.ToString()); string Rectangle = dgvImagesInDb[faceRectangleDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString(); var ImageData = dgvImagesInDb[imageBytesDataGridViewImageColumn.Index, e.RowIndex].Value; if (ImageData is byte[] ImageArray)//if ImageData is not Null. { string FaceListID = string.Empty; Task.Run(async() => { using (var db = new LiveEduFaceModel()) { Microsoft.ProjectOxford.Face.Contract.Face[] FaceDetect = null; FaceDetect = await Facial_Recognition_Library.API.ProjectOxfordAPI.DetectFace(new MemoryStream(ImageArray)); if (FaceDetect.Length > 1) { //Output the image to a temporary storage and show it to the end user WITH the Rectangles on it, this way the user can SEE the faces detected. throw new Facial_Recognition_Library.Controls.DataGridViewsFaceDetectException($@"More than one face found in this image. Please review image in temp folder {Facial_Recognition_Library.IO.FileSystemManager.TempImageLocationForErrors} "); } var FaceToUpdate = db.MyFaces.Where((f) => f.ID == FaceSystemID); foreach (var face in FaceToUpdate) { face.FaceID = FaceDetect[0].FaceId; face.DateLastDetected = DateTime.Now; } db.SaveChanges(); methodResult.Success = true; methodResult.ShouldRefreshDatabaseDataGrids = true; return(methodResult); } }); } else { System.Diagnostics.Debug.WriteLine($"Image Array was empty. You must ensure that there is an image with which to send. (cannot send 0 bytes)"); methodResult.Success = false; } return(methodResult); } else if (e.ColumnIndex == dgvImagesInDb.Columns[dgvBtnAddToCurrentFaceList.Name].Index) { System.Diagnostics.Debug.WriteLine($"Row index is {e.RowIndex}"); if (GridViewColumnsInitialized) { //TODO: Move this to the libary : dgvImagesInDb_CellClick : dgvImagesInDb.Columns[dgvBtnAddToCurrentFaceList.Name].Index Guid FaceSystemID = new Guid(dgvImagesInDb[SystemIDdgvtxtColumn.Index, e.RowIndex].Value.ToString()); string Rectangle = dgvImagesInDb[faceRectangleDataGridViewTextBoxColumn.Index, e.RowIndex].Value.ToString(); var ImageData = dgvImagesInDb[imageBytesDataGridViewImageColumn.Index, e.RowIndex].Value; byte[] ImageArray = ImageData as byte[]; if (ImageArray != null) { string FaceListID = string.Empty; using (var db = new LiveEduFaceModel()) { FaceListID = db.MyFaceLists.First().FaceListId; Microsoft.ProjectOxford.Face.Contract.FaceRectangle faceRectangle = Newtonsoft.Json.JsonConvert.DeserializeObject <Microsoft.ProjectOxford.Face.Contract.FaceRectangle>(Rectangle); var FaceListFacePersistantID = Facial_Recognition_Library.API.ProjectOxfordAPI.AddFaceToFaceListByFaceListID(FaceListID, new MemoryStream(ImageArray), null, faceRectangle).Result; var FaceToUpdate = db.MyFaces.Where((f) => f.ID == FaceSystemID); foreach (var face in FaceToUpdate) { face.FaceListPersistantID = FaceListFacePersistantID; face.DateLastDetected = DateTime.Now; } db.SaveChanges(); } } else { System.Diagnostics.Debug.WriteLine($"Image Array was empty. You must ensure that there is an image with which to send. (cannot send 0 bytes)"); methodResult.Success = false; } } else { System.Diagnostics.Debug.WriteLine($"Columns needed for lookup failed to retrieve, check the execptions list."); } return(methodResult); } } else { return(methodResult); } return(null); }