public async Task <IActionResult> FaceCompare(string IMAGE_URL1, string IMAGE_URL2) { try { bool saveFirebase; List <DetectedFace> facesDetected1 = await _cognitivevision.DetectFaceRecognize(IMAGE_URL1, RecognitionModel.Recognition03); Dictionary <string, object> dataObject1 = _firebase.TransformObjectRecognition(IMAGE_URL1, facesDetected1[0].FaceId.Value.ToString()); saveFirebase = await _firebase.SaveObject("face-reconigtion", dataObject1); if (facesDetected1.Count != 1) { throw new ArgumentException("Una de las fotos contiene ninguna o mas de una cara."); } List <DetectedFace> facesDetected2 = await _cognitivevision.DetectFaceRecognize(IMAGE_URL2, RecognitionModel.Recognition03); Dictionary <string, object> dataObject2 = _firebase.TransformObjectRecognition(IMAGE_URL2, facesDetected2[0].FaceId.Value.ToString()); saveFirebase = await _firebase.SaveObject("face-reconigtion", dataObject2); if (facesDetected2.Count != 1) { throw new ArgumentException("Una de las fotos contiene ninguna o mas de una cara."); } Guid guid1 = facesDetected1[0].FaceId.Value; Guid guid2 = facesDetected2[0].FaceId.Value; VerifyResult verifyObjectResult = await _cognitivevision.VerifyTwoFaces(guid1, guid2); Dictionary <string, object> dataObject3 = _firebase.TransformObjectCompare(verifyObjectResult, guid1, guid2); saveFirebase = await _firebase.SaveObject("face-compare", dataObject3); return(new ObjectResult(new { IsIdentical = verifyObjectResult.IsIdentical, Confidence = verifyObjectResult.Confidence }) { StatusCode = 200 }); } catch (System.Exception error) { return(new ObjectResult(new { error = error.Message, facesCount = 0 }) { StatusCode = 500 }); } }
//[Authorize] public async Task <IActionResult> FaceCompare(Guid FaceId1, Guid FaceId2) { try { VerifyResult verifyObjectResult = await _cognitivevision.VerifyTwoFaces(FaceId1, FaceId2); Dictionary <string, object> dataObject = _firebase.TransformObjectCompare(verifyObjectResult, FaceId1, FaceId2); await _firebase.SaveObject("face-compare", dataObject); return(new ObjectResult(new { IsIdentical = verifyObjectResult.IsIdentical, Confidence = verifyObjectResult.Confidence }) { StatusCode = 200 }); } catch (System.Exception error) { return(new ObjectResult(new { error = error.Message, facesCount = 0 }) { StatusCode = 500 }); } }