public async Task <String> GetVerifyAsync(string faceguid1, string faceguid2) { var client = new FaceServiceClient(ApiKey, UriBase); VerifyResult result = await client.VerifyAsync(System.Guid.Parse(faceguid1), System.Guid.Parse(faceguid2)); return(result.IsIdentical.ToString()); }
static async Task DetectAndVerifyEmployee(string personGroupId, string imgPath, Guid personId) { // This is the person we hope to find ! var person = await _faceServiceClient.GetPersonAsync(personGroupId, personId); Console.WriteLine("...Trying to confirm that the photo submitted matches with {0}", person.Name); using (Stream s = File.OpenRead(imgPath)) { var faces = await _faceServiceClient.DetectAsync(s); var faceIds = faces.Select(face => face.FaceId).ToArray(); // Here, I only care about the first face in the list of faces detected assuming there is only one. var verifyResult = await _faceServiceClient.VerifyAsync(faceIds[0], personGroupId, personId); if (verifyResult.Confidence > 0.75) { Console.WriteLine("We believe the picture correspond to: {0} with confidence: {1}\n", person.Name, verifyResult.Confidence); } else if (verifyResult.Confidence <= 0.75 && verifyResult.Confidence > 0.5) { Console.WriteLine("Humm, not too sure it's {0}, confidence is low: {1}\n", person.Name, verifyResult.Confidence); } else { Console.WriteLine("No way, you're trying to fool us, this is definitely not {0}. We got a confidence of: {1}\n", person.Name, verifyResult.Confidence); } } }
/* One way to connect to the face api,sometimes it can't get the * required faceid because the default model recognition_01 * and detection_01 is older and hence weaker. * The api it called is defined in Microsoft.ProjectOxford.Face, * however it isn't the way the tutorial shows. * Not sure what's the difference between this and * Microsoft.Azure.CognitiveServices.Vision.Face 2.2.0-preview */ public async Task TestFaceVerifyUrl(string url1, string url2) { Console.WriteLine("Detect faces:"); Console.WriteLine(url1); Console.WriteLine(url2); var uri = "https://japaneast.api.cognitive.microsoft.com/face/v1.0"; var faceAttr = new [] { FaceAttributeType.Age, FaceAttributeType.Gender, FaceAttributeType.HeadPose, FaceAttributeType.Smile, //FaceAttributeType.Emotion, }; var client = new FaceServiceClient(subscriptionKey, uri); var faces = await client.DetectAsync(url1, returnFaceAttributes : faceAttr); var faces2 = await client.DetectAsync(url2, returnFaceAttributes : faceAttr); /* The way to get the required FaceAttribute * Console.WriteLine(faces.FirstOrDefault().FaceId); * Console.WriteLine(faces.FirstOrDefault().FaceAttributes.Emotion.Happiness); */ var verifyResult = await client.VerifyAsync(faces.FirstOrDefault().FaceId, faces2.FirstOrDefault().FaceId); string message = $"The verification result is:" + $"<br> Same person:{verifyResult.IsIdentical} " + $"<br> Confidence:{verifyResult.Confidence}"; Console.WriteLine(message); await Clients.All.SendAsync("ReceiveFaceVerifyMessage", message); }
private async Task <bool> DetectarFace(HttpPostedFile file, int id) { IFaceServiceClient faceClient = new FaceServiceClient(_key, url); Face[] faces = null; Face[] faces2 = null; using (ENCONTREMEEntities db = new ENCONTREMEEntities()) { var desaperacido = db.DESAPARECIDO.Find(id); if (desaperacido != null) { using (Stream stream = new MemoryStream(Convert.FromBase64String(desaperacido.FOTO_DESAPARECIDO.Split(',')[1]))) { faces = await faceClient.DetectAsync(stream); } using (Stream stream2 = file.InputStream) { faces2 = await faceClient.DetectAsync(stream2); } if (faces != null && faces.Length > 0 && faces2 != null && faces2.Length > 0) { var retorno = await faceClient.VerifyAsync(faces[0].FaceId, faces2[0].FaceId); if (retorno.IsIdentical) { return(true); } } } } return(false); }
public async static Task <bool> DetectarFace(ComparacaoRequest request, DESAPARECIDO desaperacido) { IFaceServiceClient faceClient = new FaceServiceClient(_key, url); Face[] faces = null; Face[] faces2 = null; if (desaperacido != null) { var imgBytes1 = Convert.FromBase64String(desaperacido.FOTO_DESAPARECIDO); var imgBytes2 = Convert.FromBase64String(request.ImgBody); using (Stream stream = new MemoryStream(imgBytes1, 0, imgBytes1.Length)) { faces = await faceClient.DetectAsync(stream); } using (Stream stream2 = new MemoryStream(imgBytes2, 0, imgBytes2.Length)) { faces2 = await faceClient.DetectAsync(stream2); } if (faces != null && faces.Length > 0 && faces2 != null && faces2.Length > 0) { var retorno = await faceClient.VerifyAsync(faces[0].FaceId, faces2[0].FaceId); if (retorno.IsIdentical) { return(true); } } } return(false); }
public async Task <VerifyResult> VerifyFace(string EnterpriseId, Stream FaceStream) { bool IsVerified = false; VerifyResult result = new VerifyResult { Confidence = 0.0, IsIdentical = false }; PersonResultItem person = new PersonResultItem { EnterpriseID = EnterpriseId, PersonGroupId = ConstantsString.GroupId, // will assign new guid from service. PersonId = Guid.Empty }; var personList = await faceServiceClient.ListPersonsAsync(ConstantsString.GroupId); var responsePerson = personList.FirstOrDefault(t => t.Name == EnterpriseId); if (responsePerson != null) { person.PersonId = responsePerson.PersonId; } Face[] TobeFace = await faceServiceClient.DetectAsync(FaceStream, returnFaceLandmarks : false, returnFaceAttributes : null); if (TobeFace != null && TobeFace.Count() > 0) { Guid FaceTobeVerify = TobeFace.FirstOrDefault().FaceId; result = await faceServiceClient.VerifyAsync(FaceTobeVerify, ConstantsString.GroupId, person.PersonId); IsVerified = (result.IsIdentical || result.Confidence > 0.5) ? true : false; } return(result); }
public async Task <Face[]> GetAge() { var faceServiceClient = new FaceServiceClient("keey"); var face = await faceServiceClient.DetectAsync(this.ImageResult.Url, true, true, true, true); this.FacesCollection = face; var image = new ImageView { Edad = face[0].Attributes.Age.ToString(), Nombre = ImageResult.Nombre, Url = ImageResult.Url, Sexo = (face[0].Attributes.Gender.Equals("male")?"Hombre":"Mujer") }; var urlComparation = image.Sexo.Equals("Hombre") ? "http://aimworkout.com/wp-content/uploads/2014/11/Chuck_Norris.jpg" : "http://www.beevoz.com/wp-content/uploads/2015/08/angelinajolie.jpg"; var face1 = await faceServiceClient.DetectAsync(urlComparation); var result = await faceServiceClient.VerifyAsync(face[0].FaceId, face1[0].FaceId); image.Similar = (Convert.ToInt32(result.Confidence * 100)).ToString(); ImageCollection.Add(image); return(face); }
/// <summary> /// Verify two detected faces, get whether these two faces belong to the same person /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event argument</param> public static async Task <Microsoft.ProjectOxford.Face.Contract.VerifyResult> Verification(List <Face> faces1, List <Face> faces2) { // Call face to face verification, verify REST API supports one face to one face verification only // Here, we handle single face image only if (faces1 != null && faces2 != null && faces1.Count == 1 && faces2.Count == 1) { var faceId1 = faces1[0].FaceId; var faceId2 = faces2[0].FaceId; // Call verify REST API with two face id try { var faceServiceClient = new FaceServiceClient(KEY); return(await faceServiceClient.VerifyAsync(Guid.Parse(faceId1), Guid.Parse(faceId2))); } catch (FaceAPIException ex) { return(null); } } else { return(new Microsoft.ProjectOxford.Face.Contract.VerifyResult() { IsIdentical = false }); //var d = new MessageDialog("Verification accepts two faces as input, please pick images with only one detectable face in it.", "Warning"); //await d.ShowAsync(); //return null; } }
private async void OnCapturePhotoCompleted(IRandomAccessStream stream, IAsyncAction result, AsyncStatus status) { try { Stream streamCopy = stream.AsStreamForRead(); streamCopy.Position = 0; Face[] faces = await _faceClient.DetectAsync(streamCopy); stream.Dispose(); stream = null; bool userDetected = false; foreach (var face in faces) { VerifyResult verifyResult = await _faceClient.VerifyAsync(face.FaceId, _groupId, _personId); if (userDetected = verifyResult.IsIdentical) { break; } } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (userDetected && !_loggedOn) { txtGreeting.Text = "Hello!"; animGreeting.Begin(); _loggedOn = true; imgLogoff.Visibility = Windows.UI.Xaml.Visibility.Collapsed; imgLogon.Visibility = Windows.UI.Xaml.Visibility.Visible; itmsCalendarEvents.Visibility = Windows.UI.Xaml.Visibility.Visible; } else if (!userDetected && _loggedOn) { txtGreeting.Text = "Goodbye!"; animGreeting.Begin(); _loggedOn = false; imgLogoff.Visibility = Windows.UI.Xaml.Visibility.Visible; imgLogon.Visibility = Windows.UI.Xaml.Visibility.Collapsed; itmsCalendarEvents.Visibility = Windows.UI.Xaml.Visibility.Collapsed; } }); } catch (FaceAPIException e) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { txtException.Text = e.ErrorMessage; animException.Begin(); }); } catch (Exception) { if (stream != null) { stream.Dispose(); stream = null; } } }
public async void Azure() { FaceServiceClient face = new FaceServiceClient("02e0a76b4d34478097024cc40513d546"); var s = File.ReadAllBytes("21.png"); Face[] c = await face.DetectAsync(new MemoryStream(s)); VerifyResult vr = await face.VerifyAsync(c[0].FaceId, c[0].FaceId); }
public async void Identify() { try { string subscriptionKey = ConfigurationManager.AppSettings["subscriptionKey"].ToString(); byte[] data = System.Convert.FromBase64String(Request.Form["formfield"]); Guid face1 = new Guid(); Guid face2 = new Guid(); //byte[] data1 = System.Convert.FromBase64String(Request.Form["formfield1"]); //using (Stream imageFileStream = new MemoryStream(data)) using (Stream imageFileStream = new MemoryStream(data)) { using (var imageFileStream1 = File.OpenRead(Server.MapPath("~/images/People/bala/babal.jpg"))) { using (FaceServiceClient faceClient = new FaceServiceClient("0f79d48df54e47b5b3a298187b22bfca")) { Microsoft.ProjectOxford.Face.Contract.Face[] faces = await faceClient.DetectAsync(imageFileStream, true, true, new FaceAttributeType[] { FaceAttributeType.Gender, FaceAttributeType.Age, FaceAttributeType.Smile, FaceAttributeType.Glasses, FaceAttributeType.HeadPose, FaceAttributeType.FacialHair, FaceAttributeType.Emotion }); Microsoft.ProjectOxford.Face.Contract.Face[] faces1 = await faceClient.DetectAsync(imageFileStream1, true, true, new FaceAttributeType[] { FaceAttributeType.Gender, FaceAttributeType.Age, FaceAttributeType.Smile, FaceAttributeType.Glasses, FaceAttributeType.HeadPose, FaceAttributeType.FacialHair, FaceAttributeType.Emotion }); foreach (var f in faces) { face1 = f.FaceId; } foreach (var f in faces1) { face2 = f.FaceId; } try { var res = await faceClient.VerifyAsync(face1, face2); TextBox1.Text = string.Format("Confidence = {0:0.00}, {1}", res.Confidence, res.IsIdentical ? "two faces belong to same person" : "two faces not belong to same person"); } catch (Exception ex) { TextBox1.Text = "Error : " + ex.Message.ToString() + " Stack: " + ex.StackTrace.ToString() + " Inner:" + ex.InnerException.ToString(); } ; } } } } catch (Exception ex) { TextBox1.Text = "Error : " + ex.Message.ToString() + " Stack: " + ex.StackTrace.ToString() + " Inner:" + ex.InnerException.ToString(); //throw ex; } }
/// <summary> /// Compare people over face recognition API /// </summary> /// <param name="peopleModels">People Informations</param> public async Task MatchPhotos(List <PeopleModel> peopleModels) { FaceServiceClient client = new FaceServiceClient(SubscriptionKey, "https://westcentralus.api.cognitive.microsoft.com/face/v1.0"); List <PeopleModel> peopleFacebookList = peopleModels.Where(p => p.SocialNetworkModels.Where(x => x.SocialNetworkType.HasFlag(SocialNetworkTypes.Facebook)).Any()).ToList(); List <PeopleModel> peopleTwitterList = peopleModels.Where(p => p.SocialNetworkModels.Where(x => x.SocialNetworkType.HasFlag(SocialNetworkTypes.Twitter)).Any()).ToList(); foreach (var facebookPeople in peopleFacebookList) { try { var faces1 = await client.DetectAsync(facebookPeople.PictureUrl); foreach (var twitterPeople in peopleTwitterList) { Thread.SpinWait(500);// It's blocking when you send it fast. So we're waiting. :) try { var faces2 = await client.DetectAsync(twitterPeople.PictureUrl); if (!(faces1 == null || faces2 == null) && !(faces1.Count() == 0 || faces2.Count() == 0) && !(faces1.Count() > 1 || faces2.Count() > 1)) { try { var res = await client.VerifyAsync(faces1[0].FaceId, faces2[0].FaceId); double score = 0; if (res.IsIdentical) { score = 100; } else { score = Math.Round((res.Confidence / 0.5) * 100); } if (score >= 70 /*&& ((score == 100) ||(iPeople.Verified && jPeople.Verified) || (!iPeople.Verified && !jPeople.Verified))*/) { InsertPeople(facebookPeople, twitterPeople, score); } } catch (Exception) { } } } catch (Exception) { } } } catch (Exception ex) { } } }
public async Task <string> Verify2Faces(ObservableCollection <Face> faceCollection1, ObservableCollection <Face> faceCollection2) { //Verify var res = await faceServiceClient.VerifyAsync(Guid.Parse(faceCollection1[0].FaceId), Guid.Parse(faceCollection2[0].FaceId)); //return string.Format("Confidence = {0:0.00}, {1}", res.Confidence, //res.IsIdentical ? "Login successful" : "Face is not recognized"); return(string.Format("{1}", res.Confidence, res.IsIdentical ? "Login successful" : "Face is not recognized")); }
public async Task <string> ComprarRostros(string filename1, string filename2) { var rostros1 = await AnalizarRostros(filename1, false); var rostros2 = await AnalizarRostros(filename2, false); var result = await faceServiceClient.VerifyAsync(rostros1.FirstOrDefault().FaceId, rostros2.FirstOrDefault().FaceId); return(JsonConvert.SerializeObject(result, Formatting.Indented)); }
public static async Task <string> CompareFaceAsync(string key, string endpoint, string imageUrl) { FaceServiceClient client = new FaceServiceClient(key, endpoint); var face1 = await client.DetectAsync("http://static.independent.co.uk/s3fs-public/thumbnails/image/2013/04/25/10/Robert-Downey-Jr-Iron-Man-3-1.jpg"); var face2 = await client.DetectAsync(imageUrl); var result = await client.VerifyAsync(face1[0].FaceId, face2[0].FaceId); return($"Is Both Identical: {result.IsIdentical} <br />Confidence: {result.Confidence}"); }
public async Task <JsonResult> Upload() { try { if (Request.Files.Count != 2) { return(Json(new { error = "Error: I need two photos. Not more, not less. Two." })); } HttpPostedFileBase file1 = Request.Files[0]; HttpPostedFileBase file2 = Request.Files[1]; if (file1.ContentLength == 0 || file2.ContentLength == 0) { return(Json(new { error = "Error: It looks like the photo upload din't work..." })); } var faces1 = await client.DetectAsync(file1.InputStream); var faces2 = await client.DetectAsync(file2.InputStream); if (faces1 == null || faces2 == null) { return(Json(new { error = "Error: It looks like we can't detect faces in one of these photos..." })); } if (faces1.Count() == 0 || faces2.Count() == 0) { return(Json(new { error = "Error: It looks like we can't detect faces in one of these photos..." })); } if (faces1.Count() > 1 || faces2.Count() > 1) { return(Json(new { error = "Error: Each photo must have only one face. Nothing more, nothing less..." })); } var res = await client.VerifyAsync(faces1[0].FaceId, faces2[0].FaceId); double score = 0; if (res.IsIdentical) { score = 100; } else { score = Math.Round((res.Confidence / 0.5) * 100); } return(Json(new { error = "", result = score })); } catch (Exception ex) { return(Json(new { error = "Hmmm... Something unexpected happened. Please come back later." })); } }
private static async void VerifyFace(object s, EventArgs e) { if (Paused) { return; } var frame = GetCameraImage(); var recognizedFace = await faceClient.DetectAsync(frame.ToMemoryStream(".jpg"), returnFaceId : true); recognizedFaceID = recognizedFace.Length > 0 ? recognizedFace[0].FaceId : (Guid?)null; VerifyResult result = new VerifyResult() { Confidence = 0 }; if (recognizedFaceID != null) { result = await faceClient.VerifyAsync(myFaceID, (Guid)recognizedFaceID); } if (result.Confidence < 0.5) { lockTimer++; if (lockTimer == 1) { await Task.Run(() => MessageBox.Show(new Form() { TopMost = true }, "...", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)); } if (lockTimer > maxFailures) { LockWorkStation(); Paused = true; lockTimer = 0; } } else { lockTimer = 0; } TrayMenu.MenuItems[1].Text = $"Result ({iteration}): {result.Confidence}"; iteration++; }
private async void btnSend_Click(object sender, EventArgs e) { // 兩個Guid送至伺服器進行比較 var res = await face.VerifyAsync(System.Guid.Parse(txtFace1Guid.Text), System.Guid.Parse(txtFace2Guid.Text)); txtResult.Text = JsonConvert.SerializeObject(res); bool blIsIdentical = res.IsIdentical; double duConfidence = res.Confidence; string strMessage = "是否為同一人:" + blIsIdentical.ToString() + ", 相似度:" + duConfidence.ToString(); MessageBox.Show(strMessage); }
private async void CompareButton_Click(object sender, RoutedEventArgs e) { Stream1.Seek(0, SeekOrigin.Begin); Stream2.Seek(0, SeekOrigin.Begin); var service = new FaceServiceClient("e5571b6797284cdf90164ed342d6d628", "https://westcentralus.api.cognitive.microsoft.com/face/v1.0"); var face1 = await service.DetectAsync(Stream1); var face2 = await service.DetectAsync(Stream2); var verify = await service.VerifyAsync(face1[0].FaceId, face2[0].FaceId); CompareValue.Text = string.Format("{0:0.00}%", verify.Confidence * 100); CompareResult.Visibility = Visibility.Visible; }
/// <summary> /// Command function to verify if faces in two images is similar. Will output the result and probability in the UI /// </summary> /// <param name="obj"></param> private async void VerifyFace(object obj) { try { VerifyResult verificationResult = await _faceServiceClient.VerifyAsync(_faceId1, _faceId2); FaceVerificationResult = $"The two provided faces is identical: {verificationResult.IsIdentical}, with confidence: {verificationResult.Confidence}"; } catch (FaceAPIException ex) { Debug.WriteLine(ex.ErrorMessage); FaceVerificationResult = $"Failed to verify faces with error message: {ex.ErrorMessage}"; } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
public static async void DetecFacesAndDisplayResult(string url, string urlComparation, string id ,string campo, int value ) { var subscriptionKey = "idSupscription"; try { var client = new FaceServiceClient(subscriptionKey); var faces1 = await client.DetectAsync(url, false, true, true); var faces2 = await client.DetectAsync(urlComparation, false, true, true); if (faces1 == null || faces2 == null) { UpdateSharePoint(id, 0,campo,value); } if (faces1.Count() == 0 || faces2.Count() == 0) { UpdateSharePoint(id, 0,campo,value); } if (faces1.Count() > 1 || faces2.Count() > 1) { UpdateSharePoint(id, 0,campo,value); } var res = await client.VerifyAsync(faces1[0].FaceId, faces2[0].FaceId); double score = 0; if (res.IsIdentical) score = 100; else { score = Math.Round((res.Confidence / 0.5) * 100); } UpdateSharePoint(id, score,campo,value); } catch (Exception exception) { UpdateSharePoint(id, 0,campo,value); Console.WriteLine(exception.ToString()); } }
public async Task <List <FaceVerificationResult> > VerifyFacesMatch(string knownPersonImageUrl, string toVerifyImageUrl) { var matchResults = new List <FaceVerificationResult>(); var faceClient = new FaceServiceClient(this.Key, this.Url); var knownFaces = await faceClient.DetectAsync(knownPersonImageUrl, true, false); if (knownFaces == null || knownFaces.Length != 1) { // Not exactly one face in known photo, no match possible return(matchResults); } var knownFace = knownFaces[0]; var potentialMatches = await faceClient.DetectAsync(toVerifyImageUrl, true, false); if (potentialMatches == null || potentialMatches.Length < 1) { // no faces found in verify photo, no match possible return(matchResults); } foreach (var toVerifyFace in potentialMatches) { var verifyResult = new FaceVerificationResult(); verifyResult.FaceToVerify = toVerifyFace; verifyResult.KnownFace = knownFace; var verification = await faceClient.VerifyAsync(knownFace.FaceId, toVerifyFace.FaceId); if (verification != null) { verifyResult.IsMatch = verification.IsIdentical; verifyResult.ConfidenceLevel = verification.Confidence; } matchResults.Add(verifyResult); } return(matchResults); }
private async void OnVerifyButtonClicked(object sender, RoutedEventArgs e) { var client = new FaceServiceClient(_key, _uri); // Get a face ID for the face in the reference image var faces = await client.DetectAsync("https://prosise.blob.core.windows.net/photos/JeffProsise.jpg"); if (faces.Length == 0) { await new MessageDialog("No faces detected in reference photo").ShowAsync(); return; } Guid id1 = faces[0].FaceId; // Capture a photo of the person in front of the camera CameraCaptureUI capture = new CameraCaptureUI(); capture.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg; var file = await capture.CaptureFileAsync(CameraCaptureUIMode.Photo); using (var stream = await file.OpenStreamForReadAsync()) { // Get a face ID for the face in the photo faces = await client.DetectAsync(stream); if (faces.Length == 0) { await new MessageDialog("No faces detected in photo").ShowAsync(); return; } Guid id2 = faces[0].FaceId; // Compare the two faces var response = await client.VerifyAsync(id1, id2); await new MessageDialog("Probability that you are Jeff Prosise: " + response.Confidence.ToString()).ShowAsync(); } // Delete the storage file await file.DeleteAsync(); }
public static async Task <double> GetScoreForTwoFaces(Stream img1, Stream img2) { try { FaceServiceClient client = new FaceServiceClient("f877a6f32c314fd2b6726229f9b3a81a"); var faces1 = await client.DetectAsync(img1); var faces2 = await client.DetectAsync(img2); if (faces1 == null || faces2 == null) { var x = 1; //return Json(new { error = "Error: It looks like we can't detect faces in one of these photos..." }); } if (faces1.Count() == 0 || faces2.Count() == 0) { var x = 1; //return Json(new { error = "Error: It looks like we can't detect faces in one of these photos..." }); } if (faces1.Count() > 1 || faces2.Count() > 1) { var x = 1; //return Json(new { error = "Error: Each photo must have only one face. Nothing more, nothing less..." }); } var res = await client.VerifyAsync(faces1[0].FaceId, faces2[0].FaceId); double score = 0; if (res.IsIdentical) { score = 100; } else { score = Math.Round((res.Confidence / 0.5) * 100); } return(score); } catch (Exception ex) { return(0); } }
private async Task Verify(MainWindow mainWindowInstance) { // Call face to face verification, verify REST API supports one face to one face verification only // Here, we handle single face image only if (LeftResultCollection.Count == 1 && RightResultCollection.Count == 1) { FaceVerifyResult = "Verifying..."; var faceId1 = LeftResultCollection[0].FaceId; var faceId2 = RightResultCollection[0].FaceId; mainWindowInstance.Log(string.Format("Request: Verifying face {0} and {1}", faceId1, faceId2)); // Call verify REST API with two face id try { var faceServiceClient = new FaceServiceClient(Constants.SubscriptionKey, Constants.ApiEndpoint); var res = await faceServiceClient.VerifyAsync(Guid.Parse(faceId1), Guid.Parse(faceId2)); // Verification result contains IsIdentical (true or false) and Confidence (in range 0.0 ~ 1.0), // here we update verify result on UI by FaceVerifyResult binding FaceVerifyResult = string.Format("Confidence = {0:0.00}{1}{2}", res.Confidence, Environment.NewLine, res.IsIdentical ? "Two faces belong to same person" : "two faces not belong to same person"); mainWindowInstance.Log(string.Format("Response: Success. Face {0} and {1} {2} to the same person", faceId1, faceId2, res.IsIdentical ? "belong" : "not belong")); //if( res.IsIdentical) //{ // shutdownState = true; // mainWindowInstance.Log(string.Format("stae et rue")); //} } catch (FaceAPIException ex) { mainWindowInstance.Log(string.Format("Response: {0}. {1}", ex.ErrorCode, ex.ErrorMessage)); return; } } else { MessageBox.Show("Verification accepts two faces as input, please pick images with only one detectable face in it.", "Warning", MessageBoxButton.OK); } GC.Collect(); }
public async Task <double> VerifyFace() { var frame = GetCameraImage(); var recognizedFace = await faceClient.DetectAsync(frame.ToMemoryStream(".jpg")); recognizedFaceID = recognizedFace.Length > 0 ? recognizedFace[0].FaceId : (Guid?)null; var result = new VerifyResult() { Confidence = 0 }; if (recognizedFaceID != null) { result = await faceClient.VerifyAsync(myFaceID, (Guid)recognizedFaceID); } return(result.Confidence); }
/// <summary> /// Verify two detected faces, get whether these two faces belong to the same person /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event argument</param> private async void Face2FaceVerification_Click(object sender, RoutedEventArgs e) { // Call face to face verification, verify REST API supports one face to one face verification only // Here, we handle single face image only if (LeftResultCollection.Count == 1 && RightResultCollection.Count == 1) { FaceVerifyResult = "Verifying..."; var faceId1 = LeftResultCollection[0].FaceId; var faceId2 = RightResultCollection[0].FaceId; MainWindow.Log("Request: Verifying face {0} and {1}", faceId1, faceId2); // Call verify REST API with two face id try { MainWindow mainWindow = Window.GetWindow(this) as MainWindow; string subscriptionKey = mainWindow._scenariosControl.SubscriptionKey; string endpoint = mainWindow._scenariosControl.SubscriptionEndpoint; var faceServiceClient = new FaceServiceClient(subscriptionKey, endpoint); var res = await faceServiceClient.VerifyAsync(Guid.Parse(faceId1), Guid.Parse(faceId2)); // Verification result contains IsIdentical (true or false) and Confidence (in range 0.0 ~ 1.0), // here we update verify result on UI by FaceVerifyResult binding FaceVerifyResult = string.Format("Confidence = {0:0.00}, {1}", res.Confidence, res.IsIdentical ? "two faces belong to same person" : "two faces not belong to same person"); MainWindow.Log("Response: Success. Face {0} and {1} {2} to the same person", faceId1, faceId2, res.IsIdentical ? "belong" : "not belong"); } catch (FaceAPIException ex) { MainWindow.Log("Response: {0}. {1}", ex.ErrorCode, ex.ErrorMessage); return; } } else { MessageBox.Show("Verification accepts two faces as input, please pick images with only one detectable face in it.", "Warning", MessageBoxButton.OK); } GC.Collect(); }
public async Task<Face[]> GetAge() { var faceServiceClient = new FaceServiceClient("keey"); var face= await faceServiceClient.DetectAsync(this.ImageResult.Url,true,true,true,true); this.FacesCollection = face; var image = new ImageView { Edad = face[0].Attributes.Age.ToString(), Nombre = ImageResult.Nombre, Url = ImageResult.Url, Sexo = (face[0].Attributes.Gender.Equals("male")?"Hombre":"Mujer") }; var urlComparation = image.Sexo.Equals("Hombre") ? "http://aimworkout.com/wp-content/uploads/2014/11/Chuck_Norris.jpg" : "http://www.beevoz.com/wp-content/uploads/2015/08/angelinajolie.jpg"; var face1 = await faceServiceClient.DetectAsync(urlComparation); var result=await faceServiceClient.VerifyAsync(face[0].FaceId, face1[0].FaceId); image.Similar= (Convert.ToInt32(result.Confidence*100)).ToString(); ImageCollection.Add(image); return face; }
/// <summary> /// Verify the face with the person, get whether these two faces belong to the same person /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event argument</param> private async void Face2PersonVerification_Click(object sender, RoutedEventArgs e) { // Call face to face verification, verify REST API supports one face to one person verification only // Here, we handle single face image only if (Person != null && Person.Faces.Count != 0 && RightFaceResultCollection.Count == 1) { PersonVerifyResult = "Verifying..."; var faceId = RightFaceResultCollection[0].FaceId; MainWindow.Log("Request: Verifying face {0} and person {1}", faceId, Person.PersonName); // Call verify REST API with two face id try { MainWindow mainWindow = Window.GetWindow(this) as MainWindow; string subscriptionKey = mainWindow._scenariosControl.SubscriptionKey; string endpoint = mainWindow._scenariosControl.SubscriptionEndpoint; var faceServiceClient = new FaceServiceClient(subscriptionKey, endpoint); var res = await faceServiceClient.VerifyAsync(Guid.Parse(faceId), GroupName, Guid.Parse(Person.PersonId)); // Verification result contains IsIdentical (true or false) and Confidence (in range 0.0 ~ 1.0), // here we update verify result on UI by PersonVerifyResult binding PersonVerifyResult = string.Format("{0} ({1:0.0})", res.IsIdentical ? "the face belongs to the person" : "the face not belong to the person", res.Confidence); MainWindow.Log("Response: Success. Face {0} {1} person {2}", faceId, res.IsIdentical ? "belong" : "not belong", Person.PersonName); } catch (FaceAPIException ex) { MainWindow.Log("Response: {0}. {1}", ex.ErrorCode, ex.ErrorMessage); return; } } else { MessageBox.Show("Verification accepts one person containing face(s) and one face as input, please check.", "Warning", MessageBoxButton.OK); } GC.Collect(); }
async public Task <FamilyVerifyResult> Verification() { DateTime beginDT = DateTime.UtcNow; if (FamilyList.Count == 0) { FamilyList.Add(new FamilyClass(0, "Kevin", "http://kkcognitivestorage.blob.core.windows.net/homefaces/Family01.jpg")); FamilyList.Add(new FamilyClass(1, "Ashley", "http://kkcognitivestorage.blob.core.windows.net/homefaces/Family02.jpg")); FamilyList.Add(new FamilyClass(2, "Lynn", "http://kkcognitivestorage.blob.core.windows.net/homefaces/Family03.jpg")); await GetFamilyGUIDs(); } guestGUID = await getGUID(GuestImageStream); string memberName = ""; VerifyResult verifyResult = new VerifyResult(); foreach (var family in FamilyList) { verifyResult = await objFaceSrv.VerifyAsync(family.FaceGUID, guestGUID); if (verifyResult.IsIdentical) { memberName = family.Name; break; } } FamilyVerifyResult returnVerifyResult = new FamilyVerifyResult(); returnVerifyResult.timespend = DateTime.UtcNow - beginDT; returnVerifyResult.Confidence = verifyResult.Confidence; returnVerifyResult.IsIdentical = verifyResult.IsIdentical; returnVerifyResult.memberName = memberName; return(returnVerifyResult); }
/// <summary> /// Verify two detected faces, get whether these two faces belong to the same person /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event argument</param> private async void Verification_Click(object sender, RoutedEventArgs e) { // Call face to face verification, verify REST API supports one face to one face verification only // Here, we handle single face image only if (LeftResultCollection.Count == 1 && RightResultCollection.Count == 1) { VerifyResult = "Verifying..."; var faceId1 = LeftResultCollection[0].FaceId; var faceId2 = RightResultCollection[0].FaceId; Output = Output.AppendLine(string.Format("Request: Verifying face {0} and {1}", faceId1, faceId2)); // Call verify REST API with two face id try { MainWindow mainWindow = Window.GetWindow(this) as MainWindow; string subscriptionKey = mainWindow.SubscriptionKey; var faceServiceClient = new FaceServiceClient(subscriptionKey); var res = await faceServiceClient.VerifyAsync(Guid.Parse(faceId1), Guid.Parse(faceId2)); // Verification result contains IsIdentical (true or false) and Confidence (in range 0.0 ~ 1.0), // here we update verify result on UI by VerifyResult binding VerifyResult = string.Format("{0} ({1:0.0})", res.IsIdentical ? "Equals" : "Does not equal", res.Confidence); Output = Output.AppendLine(string.Format("Response: Success. Face {0} and {1} {2} to the same person", faceId1, faceId2, res.IsIdentical ? "belong" : "not belong")); } catch (ClientException ex) { Output = Output.AppendLine(string.Format("Response: {0}. {1}", ex.Error.Code, ex.Error.Message)); return; } } else { MessageBox.Show("Verification accepts two faces as input, please pick images with only one detectable face in it.", "Warning", MessageBoxButton.OK); } }
/// <summary> /// Verify two detected faces, get whether these two faces belong to the same person /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event argument</param> private async void Verification_Click(object sender, RoutedEventArgs e) { // Call face to face verification, verify REST API supports one face to one face verification only // Here, we handle single face image only if (LeftResultCollection.Count == 1 && RightResultCollection.Count == 1) { VerifyResult = "比对检测中..."; var faceId1 = LeftResultCollection[0].FaceId; var faceId2 = RightResultCollection[0].FaceId; Output = Output.AppendLine($"发送请求: 比对检测 面部 {faceId1} 和 {faceId2}"); // Call verify REST API with two face id try { MainWindow mainWindow = Window.GetWindow(this) as MainWindow; string subscriptionKey = mainWindow.SubscriptionKey; var faceServiceClient = new FaceServiceClient(subscriptionKey); var res = await faceServiceClient.VerifyAsync(Guid.Parse(faceId1), Guid.Parse(faceId2)); // Verification result contains IsIdentical (true or false) and Confidence (in range 0.0 ~ 1.0), // here we update verify result on UI by VerifyResult binding VerifyResult = $"{(res.IsIdentical ? "相似" : "不相似")} ({res.Confidence:0.0})"; Output = Output.AppendLine( $"反馈: 比对检测完毕. 面部 {faceId1} 和 {faceId2} {(res.IsIdentical ? "属于" : "不属于")} 同一个人"); } catch (ClientException ex) { Output = Output.AppendLine($"反馈: 出错啦 {ex.Error.Code}. {ex.Error.Message}"); } } else { MessageBox.Show("比对检测仅支持两张个人照片,请检查您的选择.", "出错了", MessageBoxButton.OK); } }
/// <summary> /// Verify two detected faces, get whether these two faces belong to the same person /// </summary> /// <param name="sender">Event sender</param> /// <param name="e">Event argument</param> private async void Verification_Click(object sender, RoutedEventArgs e) { // Call face to face verification, verify REST API supports one face to one face verification only // Here, we handle single face image only if (LeftResultCollection.Count == 1 && RightResultCollection.Count == 1) { VerifyResult = "Verifying..."; var faceId1 = LeftResultCollection[0].FaceId; var faceId2 = RightResultCollection[0].FaceId; MainWindow.Log("Request: Verifying face {0} and {1}", faceId1, faceId2); // Call verify REST API with two face id try { MainWindow mainWindow = Window.GetWindow(this) as MainWindow; string subscriptionKey = mainWindow._scenariosControl.SubscriptionKey; var faceServiceClient = new FaceServiceClient(subscriptionKey); var res = await faceServiceClient.VerifyAsync(Guid.Parse(faceId1), Guid.Parse(faceId2)); // Verification result contains IsIdentical (true or false) and Confidence (in range 0.0 ~ 1.0), // here we update verify result on UI by VerifyResult binding VerifyResult = string.Format("{0} ({1:0.0})", res.IsIdentical ? "Equals" : "Does not equal", res.Confidence); MainWindow.Log("Response: Success. Face {0} and {1} {2} to the same person", faceId1, faceId2, res.IsIdentical ? "belong" : "not belong"); } catch (FaceAPIException ex) { MainWindow.Log("Response: {0}. {1}", ex.ErrorCode, ex.ErrorMessage); return; } } else { MessageBox.Show("Verification accepts two faces as input, please pick images with only one detectable face in it.", "Warning", MessageBoxButton.OK); } }
// 저장소에 등록된 사람들인지 아닌지 확인 public async void verify(VisitorInfo info) { IFaceServiceClient faceServiceClient = new FaceServiceClient("e6edd17d1bbd4ca69d14ccf572e9af20"); string date = System.DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"); if (this.persons == null) return; //Mutex Wait //this.mutex.WaitOne(); string filepath = info.filepath; //List<Result> ret = new List<Result>(); Face[] faces = await this.UploadAndDetectFaces(filepath); List<Result> results = new List<Result>(); //얼굴이 존재하지 않을 경우 if (faces.Length == 0) { //Mutext Relase //this.mutex.Release(); Result result = new Result("No face", filepath, "No face", date); results.Add(result); xmLwriterInstance.HistoryWriting(results.ToArray()); xmLwriterInstance.AlertWriting(results.ToArray()); //xmLwriterInstance.pushXMLQueue(result); return; } Boolean verifed = false; // this.mutex.WaitOne(); // DB에 사람들과 비교하는 부분 foreach (Face face in faces) { foreach (Person person in this.persons) { if (person.faceid != null) { Guid guid = new Guid(person.faceid); /* Important region! * * The free offer provides all Face API operations that include face detection, * face verification, similar face searching, face grouping, and person identification. * With this free plan, calling to the Face APIs limits to 20 transactions * per minute and 5000 transactions per month. * * Face API의 베타 버전으로 인해 최대 1분당 20 전송량이 최대이기 때문에 제한이 걸림. */ VerifyResult verifyresult = null; try { verifyresult = await faceServiceClient.VerifyAsync(face.FaceId, guid); //DB에 저장한 사람들과 일치한 경우 if (verifyresult.IsIdentical) { Result result = new Result(person.name, filepath, person.relation); verifed = true; results.Add(result); } } catch (Exception e) { return; } } } if (verifed == false) { Result result = new Result("Unknown", filepath, "Unknown", date); results.Add(result); } else { verifed = true; } } //this.mutex.Release(); xmLwriterInstance.HistoryWriting(results.ToArray()); xmLwriterInstance.AlertWriting(results.ToArray()); //Mutext Relase //this.mutex.Release(); }
async private void button2_Click(object sender, EventArgs e) { string AccountSid = "ACd489d0930dc658a3384b1b52a28cbced"; string AuthToken = "b4f632beb8bbf85f696693d0df69dba3"; FaceServiceClient faceClient = new FaceServiceClient("0e58dbc56e5445ac8fcdfa9ffbf5ef60"); double[] ages = await UploadAndDetectFaceAges(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg", faceClient); string[] genders = await UploadAndDetectFaceGender(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg", faceClient); while(true) { VerifyResult verification = new VerifyResult(); verification.Confidence = 0; int numBoys = 0; int numgirls = 0; int ppl = 0; int avgAge = 0; int totAge = 0; if (!cam.IsRunning) { System.Threading.Thread.Sleep(1000); } bit.Save(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg"); Thread.Sleep(1000); double[] ages1 = await UploadAndDetectFaceAges(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg", faceClient); string[] genders2 = await UploadAndDetectFaceGender(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg", faceClient); StorageCredentials storageCredentials = new StorageCredentials("faceimage", "DYrgou0cTTp6J7KDdMVVxR3BDtM31zh393oyf0CfWdTuihRUgDwyryQuIqj203SnPHMJVK7VvLGm/KtfIpUncw=="); CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer container = blobClient.GetContainerReference("facecontainer"); container.CreateIfNotExistsAsync(); CloudBlockBlob blockBlob = container.GetBlockBlobReference("pic.jpg"); using (var fileStream = System.IO.File.OpenRead(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg")) { blockBlob.UploadFromStream(fileStream); } Guid[] ids = await UploadAndDetectFaceId(@"C:\Users\ma_eg_000\Desktop\PrincetonHack\pic.jpg", faceClient); InsertData(ids[0].ToString(), genders2[0], ages1[0].ToString(), "5149941737"); List<facetable> ftable = await FetchAllFaces(); string toCall = "null"; foreach(facetable fTable in ftable) { ppl++; if(fTable.Gender == "male") { numBoys++; } else { numgirls++; } totAge = totAge + Int32.Parse(fTable.Age); Guid id2 = new Guid(fTable.IdFace); VerifyResult temp = await faceClient.VerifyAsync(ids[0],id2 ); if (temp.Confidence >= verification.Confidence) { verification = temp; toCall = fTable.PhoneNumber; } } avgAge = totAge / ppl; if(verification.Confidence>= 0.40) { richTextBox1.Text = "Number of Males Customers : "+numBoys+ " Number of Female Customers :"+numgirls+ " Average age of Customers :"+avgAge; var twilio = new TwilioRestClient(AccountSid, AuthToken); var message = twilio.SendMessage("16263449948", toCall, "WE HAVE THE BEST DEALS FOR YOU TODAY!!! Free Selfie Sticks and T-Shirts Gallore", ""); } Thread.Sleep(1000); } }