public static bool IsGroom(JObject results) { //face++ const string API_Key = "Yoxjj0Tu2hUPY5D5K-iQ4ZkJoGm2W2r3"; const string API_Secret = "q97dj2QUarKmaC5NdTOdBXjC4XI2USta"; const string BaseUrl = "https://api-us.faceplusplus.com/facepp/v3/compare"; IRestClient _client; RestRequest request; if (GroomEntity.Get().Count == 0) { return(false); } string token1 = GroomEntity.Get().First().token; var faces = results["faces"].Children().ToList(); foreach (var item in faces) { string token2 = item.Last.First.ToString(); _client = new RestClient(BaseUrl); request = new RestRequest(Method.POST); request.AddParameter("api_key", API_Key); request.AddParameter("api_secret", API_Secret); request.AddParameter("face_token1", token1); request.AddParameter("face_token2", token2); var response = _client.Execute(request); JObject res = JObject.Parse(response.Content); if (double.Parse(res["confidence"].ToString()) > 80) { return(true); } } return(false); }
public static WebResult <bool> HasGroom() { try { if (GroomEntity.Get().Count == 0) { return new WebResult <bool>() { Status = true, Message = "Ok", Value = false } } ; return(new WebResult <bool>() { Status = true, Message = "Ok", Value = true }); } catch (Exception e) { return(new WebResult <bool>() { Status = false, Message = e.Message, Value = false }); } }
public static WebResult <List <ImageEntity> > InsertGroom(List <String> base64arr) { List <ImageEntity> images = null; try { images = Images.GetImages().Value; if (base64arr.Count == 2) { var base64 = Regex.Replace(base64arr[0], @"^data:image\/[a-zA-Z]+;base64,", string.Empty); byte[] byteArray = System.Convert.FromBase64String(base64); MemoryStream stream = new MemoryStream(byteArray); string urlStorage = InitImages.SendToStorage(base64arr[1], stream); if (urlStorage == "") { return new WebResult <List <ImageEntity> >() { Status = false, Message = "failed to load image", Value = images } } ; GroomEntity groom = new GroomEntity(); groom.url = urlStorage; string token = getFaceToken(urlStorage); if (token == "") { return new WebResult <List <ImageEntity> >() { Status = false, Message = "failed", Value = images } } ; groom.token = token; groom.name = base64arr[1]; if (GroomEntity.Get().ToList().Count > 0) { GroomEntity.RemoveAll(); groom.Add(); InitImagesAfterChangeGroom(); images = Images.GetImages().Value; return(new WebResult <List <ImageEntity> >() { Status = true, Message = "Ok", Value = images }); } groom.Add(); return(new WebResult <List <ImageEntity> >() { Status = true, Message = "Ok", Value = Images.GetImages().Value }); } return(new WebResult <List <ImageEntity> >() { Status = false, Message = "That's not an image", Value = images }); } catch (Exception e) { return(new WebResult <List <ImageEntity> >() { Status = false, Message = e.Message, Value = images }); } }