Exemple #1
0
        private RecoResult combineResults(List <SymbolRank> topPolar, RecoResult screenResults, int numToReturn)
        {
            List <SymbolRank> fusionResults = new List <SymbolRank>();

            foreach (SymbolRank sr in topPolar)
            {
                SymbolRank part_haus          = screenResults.getSR(ResultType.PARTIAL_HAUSDORFF, sr.Symbol);
                double     part_haus_distance = screenResults.Normalize(ResultType.PARTIAL_HAUSDORFF, part_haus);

                SymbolRank mod_haus          = screenResults.getSR(ResultType.MOD_HAUSDORFF, sr.Symbol);
                double     mod_haus_distance = screenResults.Normalize(ResultType.MOD_HAUSDORFF, mod_haus);

                SymbolRank tanim          = screenResults.getSR(ResultType.TANIMOTO, sr.Symbol);
                double     tanim_distance = screenResults.Normalize(ResultType.TANIMOTO, tanim);

                SymbolRank yule          = screenResults.getSR(ResultType.YULE, sr.Symbol);
                double     yule_distance = 1 - screenResults.Normalize(ResultType.YULE, yule);

                double distance = part_haus_distance + mod_haus_distance + tanim_distance + yule_distance;

                fusionResults.Add(new SymbolRank(distance, sr.Symbol, sr.BestOrientation));
            }

            // sort
            var sortedResults = from result in fusionResults
                                orderby result.Distance ascending
                                select result;

            RecoResult combinedResults = new RecoResult();

            combinedResults.AddRange(ResultType.FUSION, sortedResults.Take(numToReturn));
            return(combinedResults);
        }
Exemple #2
0
 public void AddAll(RecoResult otherResults)
 {
     foreach (ResultType type in Enum.GetValues(typeof(ResultType)))
     {
         _results[type].AddRange(otherResults._results[type]);
     }
 }
Exemple #3
0
        private RecoResult polarRecognition(List <BitmapSymbol> defns)
        {
            RecoResult results = new RecoResult();

            foreach (BitmapSymbol bs in defns)
            {
                SymbolRank polar_result = Polar_Mod_Hausdorff(bs);
                results.Add(ResultType.POLAR, polar_result);
            }
            return(results);
        }
Exemple #4
0
 public BitmapSymbol()
 {
     _name         = "";
     _type         = new ShapeType();
     _results      = new RecoResult();
     _id           = Guid.NewGuid();
     _points       = new BitmapPoints();
     _screenCoords = new List <Coord>();
     _sMesh        = new GeneralMatrix(GRID_Y_SIZE, GRID_X_SIZE, 0.0);
     _sDTM         = new GeneralMatrix(GRID_Y_SIZE, GRID_X_SIZE, double.PositiveInfinity);
     _polarCoords  = new List <Coord>();
     _pMesh        = new GeneralMatrix(GRID_Y_SIZE, GRID_X_SIZE, 0.0);
     _pDTM         = new GeneralMatrix(GRID_Y_SIZE, GRID_X_SIZE, double.PositiveInfinity);
 }
Exemple #5
0
        public object Clone()
        {
            RecoResult result = (RecoResult)this.MemberwiseClone();

            result._results = new Dictionary <ResultType, List <SymbolRank> >();
            foreach (KeyValuePair <ResultType, List <SymbolRank> > pair in _results)
            {
                result._results.Add(pair.Key, new List <SymbolRank>());
                foreach (SymbolRank sr in pair.Value)
                {
                    result._results[pair.Key].Add((SymbolRank)sr.Clone());
                }
            }

            return(result);
        }
Exemple #6
0
        private RecoResult screenRecognition(List <SymbolRank> topPolar)
        {
            RecoResult screenResults = new RecoResult();

            foreach (SymbolRank sr in topPolar)
            {
#if JESSI
                Console.WriteLine();
                Console.WriteLine("Doing screen recognition for template " + sr.SymbolName);
#endif
                // clone the BitmapSymbol so that we can rotate it without losing information
                BitmapSymbol clone = (BitmapSymbol)Clone();
                clone.Rotate(-sr.BestOrientation);

                // calculate the data using the rotated clone, but store the output in this symbol's results.
                screenResults.Add(ResultType.PARTIAL_HAUSDORFF, clone.Partial_Hausdorff(sr.Symbol));
                screenResults.Add(ResultType.MOD_HAUSDORFF, clone.Modified_Hausdorff(sr.Symbol));
                screenResults.Add(ResultType.TANIMOTO, clone.Tanimoto_Distance(sr.Symbol));
                screenResults.Add(ResultType.YULE, clone.Yule_Distance(sr.Symbol));
            }
            return(screenResults);
        }
Exemple #7
0
        public RecoResult Recognize(List <BitmapSymbol> defns)
        {
            if (defns.Count == 0)
            {
                throw new ArgumentException("You must provide a nonempty list of templates!");
            }

            int numTopPolarToKeep       = Math.Min(NUM_TOP_POLAR_TO_KEEP, defns.Count);
            int numRecognitionsToReturn = Math.Min(NUM_RECOGNITIONS_TO_RETURN, defns.Count);

            RecoResult polarResults = polarRecognition(defns);

#if JESSI
            Console.WriteLine("\nThese templates made it through the polar recognition round:");
            foreach (SymbolRank sr in polarResults.BestN(ResultType.POLAR, NUM_TOP_POLAR_TO_KEEP))
            {
                Console.WriteLine(sr.SymbolName);
            }
#endif

            List <SymbolRank> topPolar        = polarResults.BestN(ResultType.POLAR, numTopPolarToKeep);
            RecoResult        screenResults   = screenRecognition(topPolar);
            RecoResult        combinedResults = combineResults(topPolar, screenResults, numRecognitionsToReturn);

#if JESSI
            Console.WriteLine("Your templates have now been reordered by screen recognition:");
            foreach (SymbolRank sr in combinedResults.BestN(ResultType.FUSION, NUM_TOP_POLAR_TO_KEEP))
            {
                Console.WriteLine(sr.SymbolName);
            }
#endif

            combinedResults.AddAll(polarResults);
            combinedResults.AddAll(screenResults);
            return(combinedResults);
        }