private LambdaRebuildAlbumResponse RebuildAlbum(string albumId) { string responseJson = Unirest.get(BaseUrl + "album_rebuild" + string.Format("?album={0}&albumkey={1}", AlbumName, albumId)) .header("X-Mashape-Key", ApiKeys.GetCurrentKey()) .header("Accept", "application/json") .asString().Body; return(JsonConvert.DeserializeObject <LambdaRebuildAlbumResponse>(responseJson)); }
private LambdaCreateAlbumResponse CreateAlbum() { string responseJson = Unirest.post(BaseUrl + "album") .header("X-Mashape-Key", ApiKeys.GetCurrentKey()) .header("Accept", "application/json") .field("album", Guid.NewGuid()) .asString().Body; return(JsonConvert.DeserializeObject <LambdaCreateAlbumResponse>(responseJson)); }
private AnimetricsDetectResponse DetectFace(MemoryStream stream) { string responseJson = Unirest.post(BaseUrl + "detect") .header("Accept", "application/json") .field("api_key", ApiKeys.GetCurrentKey()) .field("selector", "FULL") .field("image", stream.ToArray()) .asString().Body; AnimetricsDetectResponse response = JsonConvert.DeserializeObject <AnimetricsDetectResponse>(responseJson); return(response); }
private List <LambdaRecognizeResponse> RecognizePhotos(string albumId) { List <LambdaRecognizeResponse> result = new List <LambdaRecognizeResponse>(); foreach (var entry in DataSet.SourceImages) { MemoryStream imageStream = new MemoryStream(); DataSet.GetImage(entry.Key).Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] data = imageStream.ToArray(); var watch = Stopwatch.StartNew(); string responseJson = Unirest.post(BaseUrl + "recognize") .header("X-Mashape-Key", ApiKeys.GetCurrentKey()) .header("Accept", "application/json") .field("album", AlbumName) .field("albumkey", albumId) .field("files", data) .asString().Body; watch.Stop(); TimingResults.Add(new TimingModel("RecognizePhotos", entry.Key, watch.ElapsedMilliseconds)); LambdaRecognizeResponse response = JsonConvert.DeserializeObject <LambdaRecognizeResponse>(responseJson); if (response.status != "success") { Console.WriteLine("API failed at image {0}.", entry.Key); } else { result.Add(response); try { if (response.photos[0].tags[0].uids == null) { Console.WriteLine("Image {0} not recognized.", entry.Key); } else { string prediction = response.photos[0].tags[0].uids[0].prediction; double confidence = response.photos[0].tags[0].uids[0].confidence; Console.WriteLine("Image {0} recognized as {1} with {2} confidence.", entry.Key, prediction, confidence); } } catch (Exception e) { Console.WriteLine("Encountered some weird exception"); } } } return(result); }
private AnimetricsEnrollResponse EnrollFace(KeyValuePair <string, AnimetricsDetectResponse> entry) { HttpResponse <string> response = Unirest.post(BaseUrl + "detect") .header("Accept", "application/json") .field("api_key", ApiKeys.GetCurrentKey()) .field("subject_id", entry.Key) .field("gallery_id", GalleryId) .field("image_id", entry.Value.images[0].image_id) .field("topLeftX", entry.Value.images[0].faces[0].topLeftX) .field("topLeftY", entry.Value.images[0].faces[0].topLeftY) .field("width", entry.Value.images[0].width) .field("height", entry.Value.images[0].height) .asString(); return(JsonConvert.DeserializeObject <AnimetricsEnrollResponse>(response.Body)); }
private AnimetricsRecognizeResponse RecognizeFace(KeyValuePair <string, AnimetricsDetectResponse> entry) { var watch = Stopwatch.StartNew(); HttpResponse <string> response = Unirest.post(BaseUrl + "detect") .header("Accept", "application/json") .field("api_key", ApiKeys.GetCurrentKey()) .field("gallery_id", GalleryId) .field("image_id", entry.Value.images[0].image_id) .field("max_num_results", 10) .field("topLeftX", entry.Value.images[0].faces[0].topLeftX) .field("topLeftY", entry.Value.images[0].faces[0].topLeftY) .field("width", entry.Value.images[0].width) .field("height", entry.Value.images[0].height) .asString(); watch.Stop(); TimingResults.Add(new TimingModel("RecognizeFace", entry.Key, watch.ElapsedMilliseconds)); return(JsonConvert.DeserializeObject <AnimetricsRecognizeResponse>(response.Body)); }
private List <LambdaTrainAlbumResponse> TrainAlbum(string albumId) { List <LambdaTrainAlbumResponse> result = new List <LambdaTrainAlbumResponse>(); foreach (var entry in DataSet.TargetImages) { MemoryStream imageStream = new MemoryStream(); DataSet.GetImage(entry.Key).Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] data = imageStream.ToArray(); // For some reason LambdaLabs is really picky about what characters they allow in an entry id string entryId = entry.Key.Split('/')[1].Split('.')[0].Replace("_", ""); HttpResponse <string> response = Unirest.post(BaseUrl + "album_train") .header("X-Mashape-Key", ApiKeys.GetCurrentKey()) .header("accept", "application/json") .field("album", AlbumName) .field("albumkey", albumId) .field("entryid", entryId) .field("files", data) .asString(); LambdaTrainAlbumResponse responseObject = JsonConvert.DeserializeObject <LambdaTrainAlbumResponse>(response.Body); if (responseObject.entryid != null) { Console.WriteLine("Face detected in image {0}.", entry.Key); result.Add(responseObject); } else { Console.WriteLine("No face detected in image {0}.", entry.Key); } } return(result); }