public static void UpdateNameAndVoiceURL(int objId, int voiceNumber, string newname) { string url = BLLtextToSpeach.TextToSpeach(newname); //url = BLLtextToSpeach.VoiceStorage(1, BLLimage.GetImageById(BLLobject.GetObjectById(objId).ImageID).CategoryID, url, voiceNumber); DALimageObject.UpdateNameAndVoiceURL(objId, voiceNumber, newname, url); }
// [HttpPost] public void PostObjects([FromBody] List <COMimageObject> objs, int id, int catid) { try { COMimage img = new COMimage(); img.UserId = id; img.CategoryID = catid; img.URL = ""; int imageid = BLLgoogleVision.UserImageStorageAndDB(img, objs[0].VoiceURL); Dictionary <string, int> dic = new Dictionary <string, int>(); foreach (COMimageObject item in objs) { item.ImageID = imageid; item.VoiceURL = BLLtextToSpeach.VoiceStorage(id, catid, BLLtextToSpeach.TextToSpeach(item.Name), dic); BLLobject.AddObject(item); } } catch (Exception) { //return BadRequest(); throw; } }
public static List <string> VisionApi(int categoryId, int UserId, string URL, Dictionary <string, int> categoriesCounter, Dictionary <string, int> voicesCounter) { Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", @"C:\keys\wordproject-29b2e0d3e0d5.json"); // Instantiates a client var client = ImageAnnotatorClient.Create(); // Load the image file into memory var image = Image.FromFile(URL); // Performs label detection on the image file var response = client.DetectLocalizedObjects(image);// //found most common word in objects list Dictionary <string, int> countingDic = new Dictionary <string, int>(); string common = string.Empty; foreach (var annotation in response) { if (countingDic.ContainsKey(annotation.Name)) { int max = 1; countingDic[annotation.Name]++; if (max < countingDic[annotation.Name]) { max = countingDic[annotation.Name]; common = annotation.Name; } } else { countingDic.Add(annotation.Name, 1); } } COMimage img = new COMimage(); string imgUrl; List <string> ans = new List <string>(); int c = 0; int imgId = -1; try { imgUrl = Storage(categoryId, URL, categoriesCounter); // if image in storage //insert image info db img.CategoryID = categoryId; img.URL = imgUrl; img.UserId = UserId; //DALimageObject.Refresh(); img.BeginIndex = BLLobject.GetObjects().Count; DALimage.Addimage(img); imgId = DALimage.GetImageIdByURL(img.URL); //insert objects into db Dictionary <Bounding, string> finalList = new Dictionary <Bounding, string>(); foreach (var annotation in response) { List <double> x = new List <double>(); List <double> y = new List <double>(); foreach (var item in annotation.BoundingPoly.NormalizedVertices) { x.Add(item.X); y.Add(item.Y); } bool help = false; Bounding bounding = new Bounding(x, y); //if there is item with same bounding box and the existing is common name and the new not- swap them. foreach (var item in finalList) { if (item.Key.IsEqual(bounding)) { help = true; if (item.Value == common && annotation.Name != common) { finalList.Remove(item.Key); finalList.Add(bounding, annotation.Name); } } } if (help == false) { finalList.Add(bounding, annotation.Name); } else { help = true; } } foreach (var item in finalList) { COMimageObject obj = new COMimageObject(); obj.ImageID = imgId; obj.Name = item.Value; obj.X1 = item.Key.X1; obj.X2 = item.Key.X2; obj.X3 = item.Key.X3; obj.X4 = item.Key.X4; obj.Y1 = item.Key.Y1; obj.Y2 = item.Key.Y2; obj.Y3 = item.Key.Y3; obj.Y4 = item.Key.Y4; try { obj.VoiceURL = BLLtextToSpeach.VoiceStorage(UserId, BLLimage.GetImageById(obj.ImageID).CategoryID, BLLtextToSpeach.TextToSpeach(obj.Name), voicesCounter); } catch (Exception e) { throw e; } DALimageObject.AddObject(obj); c++; ans.Add(obj.Name); } } catch (Exception e) { throw e; } return(ans); }