public static List <String> Searching(Dictionary <String, List <String> > dicVisualWords, List <Dot_RGB> listDot, Size input) { if (listDot == null || listDot.Count == 0) { return(null); } float cellWidth = input.Width / (float)ConfigPCT.PCT_NUMBER_OF_HORIZONTAL_REGION; float cellHeight = input.Height / (float)ConfigPCT.PCT_NUMBER_OF_VERTICAL_REGION; Dot_RGB dot = listDot[0]; int xIndex = (int)(listDot[0].location.X / cellWidth); int yIndex = (int)(listDot[0].location.Y / cellHeight); List <Color> colorVisualWord = ColorHelper.GenerateColorVisualWord_Rgb(); Color color = colorVisualWord[DistanceHelper.ColorKNN_RGB(dot.color, colorVisualWord)]; String key = color.R + "_" + color.G + "_" + color.B + "_" + xIndex + "_" + yIndex; if (dicVisualWords.ContainsKey(key)) { return(dicVisualWords[key]); } return(null); }
public static List <String> SearchingV3_RGB(Dictionary <string, string> dicVisualWords, List <Dot_RGB> listDotDrawn, Size paperDrawingSize) { if (listDotDrawn == null || listDotDrawn.Count == 0) { return(null); } // init bool SEARCH_MULTI_REGION_FOR_INPUT_DOTS = true; List <Color> colorsVisualWord = ColorHelper.GenerateColorVisualWord_Rgb(); // Get list visual-words match the list input colors >> dicMatched Dictionary <string, List <string> > dicInputColorsMatchedTheIndex = new Dictionary <string, List <string> >(); List <string> listKeyMatchTheInputDot = new List <string>(); foreach (Dot_RGB dot in listDotDrawn) { Color color = colorsVisualWord[DistanceHelper.ColorKNN_RGB(dot.color, colorsVisualWord)]; List <RegionOfFrame> listRegionsDotBelongTo = Utils.RegionOfFrameHelper.GetListRegionDotBelongTo(dot.location, dot.radius, paperDrawingSize.Width, paperDrawingSize.Height); foreach (RegionOfFrame region in listRegionsDotBelongTo) { string key = color.R + "_" + color.G + "_" + color.B + "_" + region.X + "_" + region.Y; //if (!dicInputColorsMatchedTheIndex.ContainsKey(key)) //{ // dicInputColorsMatchedTheIndex.Add(key, dicVisualWords[key]); //} if (!listKeyMatchTheInputDot.Contains(key)) { listKeyMatchTheInputDot.Add(key); } if (!SEARCH_MULTI_REGION_FOR_INPUT_DOTS) { break; } } } // Intersect all item in dicMatched (để lọc bỏ frame trùng ở kết quả) //List<string> listFramesResult = dicInputColorsMatchedTheIndex.ElementAt(0).Value; List <string> listFramesResult = FileManager.GetInstance().GetAllLinesFromFile(dicVisualWords[listKeyMatchTheInputDot[0]].Replace("D:", ConfigCommon.PCT_INDEX_STORAGE[0] + ":")); for (int i = 1; i < listKeyMatchTheInputDot.Count; i++) { //listFramesResult = dicInputColorsMatchedTheIndex.ElementAt(i).Value.Intersect(listFramesResult).ToList(); List <string> listFrame = FileManager.GetInstance().GetAllLinesFromFile(dicVisualWords[listKeyMatchTheInputDot[i]].Replace("D:", ConfigCommon.PCT_INDEX_STORAGE[0] + ":")); listFramesResult = listFramesResult.Intersect(listFrame).ToList(); } return(listFramesResult); }
public static List <String> SearchingV2_RGB(Dictionary <string, List <string> > dicVisualWords, List <Dot_RGB> listDotDrawn, Size paperDrawingSize) { if (listDotDrawn == null || listDotDrawn.Count == 0) { return(null); } // init bool SEARCH_MULTI_REGION_FOR_INPUT_DOTS = true; List <Color> colorsVisualWord = ColorHelper.GenerateColorVisualWord_Rgb(); // Get list visual-words match the list input colors >> dicMatched Dictionary <string, List <string> > dicInputColorsMatchedTheIndex = new Dictionary <string, List <string> >(); foreach (Dot_RGB dot in listDotDrawn) { Color color = dot.color; color = colorsVisualWord[DistanceHelper.ColorKNN_RGB(dot.color, colorsVisualWord)]; List <RegionOfFrame> listRegionsDotBelongTo = Utils.RegionOfFrameHelper.GetListRegionDotBelongTo(dot.location, dot.radius, paperDrawingSize.Width, paperDrawingSize.Height); foreach (RegionOfFrame region in listRegionsDotBelongTo) { String key = color.R + "_" + color.G + "_" + color.B + "_" + region.X + "_" + region.Y; if (!dicInputColorsMatchedTheIndex.ContainsKey(key)) { dicInputColorsMatchedTheIndex.Add(key, dicVisualWords[key]); } if (!SEARCH_MULTI_REGION_FOR_INPUT_DOTS) { break; } } } // Intersect all item in dicMatched List <string> listFramesResult = dicInputColorsMatchedTheIndex.ElementAt(0).Value; for (int i = 1; i < dicInputColorsMatchedTheIndex.Count; i++) { listFramesResult = dicInputColorsMatchedTheIndex.ElementAt(i).Value.Intersect(listFramesResult).ToList(); } return(listFramesResult); }
private static int CountColorsVW_RGB(PCTFeature_RGB pct, List <Color> colorVisualWord) { //Dictionary<String, Color> map = new Dictionary<string, Color>(); List <string> listColorVWs = new List <string>(); foreach (var item in pct.ListColorPoint) { Color color = colorVisualWord[DistanceHelper.ColorKNN_RGB(item.color, colorVisualWord)]; String key = color.R + "_" + color.G + "_" + color.B; if (!listColorVWs.Contains(key)) { listColorVWs.Add(key); } //if (!map.ContainsKey(key)) // map.Add(key, color); } //int totalColor = map.Count; //return totalColor; return(listColorVWs.Count); }
public static void RunIndexing_RGB(string imageIndexStoragePath) { #region init List <Color> visualWordColor = ColorHelper.GenerateColorVisualWord_Rgb(); // * Dictionary <string, List <string> > visualWordMain = new Dictionary <String, List <string> >(); List <VisualWordCell_RGB> listKeys = VisualWordHelper.CreateListVWKeys_Rgb(); // * foreach (var item in listKeys) { // * String key = item.Color.R + "_" + item.Color.G + "_" + item.Color.B + "_" + item.XIndex + "_" + item.YIndex; visualWordMain.Add(key, new List <String>()); } string indexFileNameExtension = GetIndexFileNameExtension(); #endregion // for each folder int count = 0; string[] SubDirs = Directory.GetDirectories(ConfigCommon.PCT_OUTPUT_PATH); foreach (String folderPath in SubDirs) { Console.WriteLine((++count) + ". " + folderPath); FileInfo[] fileInfos = FileManager.GetInstance().GetAllFileInFolder(folderPath); int sizeFiles = fileInfos.Length; // for each X file (X = PCTConfig.PCT_STEP_INDEX_FILE) for (int i = 0; i < sizeFiles; i += ConfigPCT.PCT_STEP_INDEX_FILE) { // read data PCT from file PCTFeature_RGB dataPCT = PCTReadingFeature.ReadingFeatureFromFile_RGB(fileInfos[i].FullName); // * // if number of color visual-word > Y, skip (Y = PCTConfig.COLOR_NOISE_THRESHOLD) int numberColor = CountColorsVW_RGB(dataPCT, visualWordColor); if (numberColor > ConfigPCT.COLOR_NOISE_THRESHOLD) { continue; } foreach (Dot_RGB colorPoint in dataPCT.ListColorPoint) { // if radius >= Z, index it (Z = PCTConfig.RADIUS_THRESHOLD) if (colorPoint.radius >= ConfigPCT.RADIUS_THRESHOLD) { List <RegionOfFrame> listRegionDotBelongTo = Utils.RegionOfFrameHelper.GetListRegionDotBelongTo(colorPoint.location, colorPoint.radius, dataPCT.Width, dataPCT.Height); Color color = visualWordColor[DistanceHelper.ColorKNN_RGB(colorPoint.color, visualWordColor)]; foreach (RegionOfFrame region in listRegionDotBelongTo) { String key = color.R + "_" + color.G + "_" + color.B + "_" + region.X + "_" + region.Y; visualWordMain[key].Add(dataPCT.FrameName); } } } } } foreach (var item in listKeys) { string key = item.Color.R + "_" + item.Color.G + "_" + item.Color.B + "_" + item.XIndex + "_" + item.YIndex; visualWordMain[key] = visualWordMain[key].Distinct().ToList(); } // save the indexing to a file //String json = JsonConvert.SerializeObject(visualWordMain); //FileManager.GetInstance().WriteFile(json, Path.Combine(imageIndexStoragePath, "index.json")); string fileSavePath = Path.Combine(imageIndexStoragePath, indexFileNameExtension); if (File.Exists(fileSavePath)) { File.Delete(fileSavePath); } FileManager.GetInstance().WriteDicIndexingToFiles(visualWordMain, fileSavePath); }