Example #1
0
        public override bool Equals(object obj)
        {
            if (obj == null || !(obj is SubstrokeCollection))
            {
                return(false);
            }

            if (obj == this)
            {
                return(true);
            }

            SubstrokeCollection collection = (SubstrokeCollection)obj;

            if (collection.Count != Count)
            {
                return(false);
            }

            for (int i = 0; i < Count; i++)
            {
                if (collection._substrokes[i].Id != _substrokes[i].Id)
                {
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
 /// <summary>
 /// Get an estimate of the probability that the given shape is of the given type
 /// </summary>
 /// <param name="shape"></param>
 /// <param name="type"></param>
 /// <param name="orientation">[out] the best orientation for the given type</param>
 /// <returns>the probability</returns>
 private RecognitionResult RecognizeAsType(
     SubstrokeCollection substrokes,
     ShapeType type,
     FeatureSketch featureSketch)
 {
     if (!_identificationResults.ContainsKey(substrokes))
     {
         _identificationResults.Add(substrokes, computeRecognitionProbabilities(substrokes, featureSketch));
     }
     return(_identificationResults[substrokes][type]);
 }
Example #3
0
        /// <summary>
        /// Compute the probability that a given set of substrokes has the given type.
        /// </summary>
        /// <param name="substrokes"></param>
        /// <param name="type"></param>
        /// <param name="featureSketch"></param>
        /// <returns>a pair containing the recognition probability and the orientation</returns>
        private RecognitionResult computeRecognitionProbabilityForTextOrWire(SubstrokeCollection substrokes, ShapeType type, FeatureSketch featureSketch)
        {
            double probability = 0;
            double orientation = 0;

            PhantomShape shape = new PhantomShape();

            shape.AddSubstrokes(substrokes);

            if (LogicDomain.IsWire(type))
            {
                // the probability it is a wire is defined as
                // (# substrokes classified as wires) / (total # substrokes)

                int numSubstrokes     = substrokes.Count;
                int numWireSubstrokes = 0;

                foreach (Substroke substroke in substrokes)
                {
                    if (_classifications[substroke] == LogicDomain.WIRE_CLASS)
                    {
                        numWireSubstrokes++;
                    }
                }

                probability = (double)numWireSubstrokes / numSubstrokes;
                return(new RecognitionResult(LogicDomain.WIRE, probability, orientation));
            }
            else if (LogicDomain.IsText(type))
            {
                // the probability it is text is defined as
                // (# substrokes classified as text) / (total # substrokes)

                int numSubstrokes     = substrokes.Count;
                int numTextSubstrokes = 0;

                foreach (Substroke substroke in substrokes)
                {
                    if (_classifications[substroke] == LogicDomain.TEXT_CLASS)
                    {
                        numTextSubstrokes++;
                    }
                }

                probability = (double)numTextSubstrokes / numSubstrokes;
                return(new TextRecognitionResult(probability, _textRecognizer.read(shape)));
            }

            return(null);
        }
Example #4
0
        /// <summary>
        /// Suppose that the given substrokes form a shape. What is the most likely type for it?
        /// </summary>
        /// <param name="substrokes"></param>
        /// <param name="featureSketch"></param>
        /// <returns></returns>
        private RecognitionResult Identify(SubstrokeCollection substrokes, Featurefy.FeatureSketch featureSketch)
        {
            RecognitionResult best = null;

            foreach (ShapeType type in LogicDomain.Types)
            {
                RecognitionResult result = RecognizeAsType(substrokes, type, featureSketch);
                double            prob   = result.Confidence;
                if (best == null || prob > best.Confidence)
                {
                    best = result;
                }
            }
            return(best);
        }
Example #5
0
        /// <summary>
        /// For each type, get an estimate of the probability that the given shape is of the given type
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="shape"></param>
        /// <param name="types"></param>
        /// <param name="featureSketch"></param>
        /// <returns></returns>
        private Dictionary <ShapeType, RecognitionResult> computeRecognitionProbabilities(
            SubstrokeCollection substrokes,
            FeatureSketch featureSketch)
        {
            PhantomShape shape = new PhantomShape();

            shape.AddSubstrokes(substrokes);

            Dictionary <ShapeType, RecognitionResult> results = Data.Utils.replaceValues(
                _gateRecognizer.RecognitionResults(shape, LogicDomain.Gates),
                r => { return((RecognitionResult)r); });

            foreach (ShapeType type in LogicDomain.Types)
            {
                if (!results.ContainsKey(type))
                {
                    results.Add(type, computeRecognitionProbabilityForTextOrWire(substrokes, type, featureSketch));
                }
            }

            return(results);
        }