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);
        }
示例#2
0
        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 }));
        }