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 <IHttpActionResult> CompararImagem([FromBody] ComparacaoRequest request) { var resultado = false; using (ENCONTREMEEntities db = new ENCONTREMEEntities()) { var desaperacido = db.DESAPARECIDO.Find(request.Id); resultado = await DetectarFace(request, desaperacido); } return(Ok(new { resultado = resultado })); }