Example #1
0
        public static List <String> SearchingV3_Lab(Dictionary <string, string> dicVisualWords, List <Dot_Lab> listDotDrawn, Size paperDrawingSize)
        {
            if (listDotDrawn == null || listDotDrawn.Count == 0)
            {
                return(null);
            }

            // init
            bool       SEARCH_MULTI_REGION_FOR_INPUT_DOTS = true;
            List <Lab> colorsVisualWord = ColorHelper.GenerateColorVisualWord_Lab();

            // 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_Lab dot in listDotDrawn)
            {
                Lab color = colorsVisualWord[DistanceHelper.ColorKNN_Lab(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.L + "_" + color.A + "_" + 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);
        }
        private static int CountColorsVW_Lab(PCTFeature_Lab pct, List <Lab> colorVisualWord)
        {
            //Dictionary<String, Color> map = new Dictionary<string, Color>();
            List <Lab> listColorVWs = new List <Lab>();

            foreach (var item in pct.ListColorPoint)
            {
                Lab color = colorVisualWord[DistanceHelper.ColorKNN_Lab(item.color, colorVisualWord)];
                if (!listColorVWs.Contains(color))
                {
                    listColorVWs.Add(color);
                }
                //if (!map.ContainsKey(key))
                //    map.Add(key, color);
            }
            //int totalColor = map.Count;
            //return totalColor;
            return(listColorVWs.Count);
        }
Example #3
0
        public static List <String> SearchingV2_Lab(Dictionary <string, List <string> > dicVisualWords, List <Dot_Lab> listDotDrawn, Size paperDrawingSize)
        {
            if (listDotDrawn == null || listDotDrawn.Count == 0)
            {
                return(null);
            }

            // init
            bool       SEARCH_MULTI_REGION_FOR_INPUT_DOTS = true;
            List <Lab> colorsVisualWord = ColorHelper.GenerateColorVisualWord_Lab();

            // Get list visual-words match the list input colors >> dicMatched
            Dictionary <string, List <string> > dicInputColorsMatchedTheIndex = new Dictionary <string, List <string> >();

            foreach (Dot_Lab dot in listDotDrawn)
            {
                Lab color = dot.color;
                color = colorsVisualWord[DistanceHelper.ColorKNN_Lab(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.L + "_" + color.A + "_" + 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);
        }
        public static void RunIndexing_Lab(string imageIndexStoragePath)
        {
            #region init
            List <Lab> visualWordColor = ColorHelper.GenerateColorVisualWord_Lab();                       // *
            Dictionary <string, List <string> > visualWordMain = new Dictionary <string, List <string> >();
            List <VisualWordCell_Lab>           listKeys       = VisualWordHelper.CreateListVWKeys_Lab(); // *
            foreach (var item in listKeys)
            {
                // *
                string key = item.Color.L + "_" + item.Color.A + "_" + 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_Lab dataPCT = PCTReadingFeature.ReadingFeatureFromFile_Lab(fileInfos[i].FullName); // *

                    // if number of color visual-word > Y, skip (Y = PCTConfig.COLOR_NOISE_THRESHOLD)
                    int numberColor = CountColorsVW_Lab(dataPCT, visualWordColor);
                    if (numberColor > ConfigPCT.COLOR_NOISE_THRESHOLD)
                    {
                        continue;
                    }

                    foreach (Dot_Lab 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);
                            Lab color = visualWordColor[DistanceHelper.ColorKNN_Lab(colorPoint.color, visualWordColor)];

                            foreach (RegionOfFrame region in listRegionDotBelongTo)
                            {
                                //Key_PCTIndexDicLab key = new Key_PCTIndexDicLab(color.L, color.A, color.B, region.X + "_" + region.Y);
                                string key = color.L + "_" + color.A + "_" + color.B + "_" + region.X + "_" + region.Y;
                                visualWordMain[key].Add(dataPCT.FrameName);
                                //if (!visualWordMain[key].Contains(dataPCT.FrameName)) // slow
                                //    visualWordMain[key].Add(dataPCT.FrameName);
                            }
                        }
                    }
                }
            }

            foreach (var item in listKeys)
            {
                string key = item.Color.L + "_" + item.Color.A + "_" + item.Color.B + "_" + item.XIndex + "_" + item.YIndex;
                Console.WriteLine("Distincting value of key " + key + " ...");
                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().WriteDicIndexingToJsonFile(visualWordMain, fileSavePath);
            FileManager.GetInstance().WriteDicIndexingToFiles(visualWordMain, fileSavePath);
        }