Ejemplo n.º 1
0
        /// <summary>
        /// Loads a previously saved AdaptiveImageRecognizer from the given filename,
        /// using the deserialization constructor.
        ///
        /// This function is used primarily for testing, because the number of templates
        /// per gate should be fixed when using the program. This allows you to change it
        /// if you so desire.
        /// </summary>
        /// <param name="filename">Filename which is the saved AdaptiveImageRecognizer</param>
        /// <param name="NumTemplatesPerGate">The maximum number of templates per gate to store</param>
        /// <returns>Re-instantiated AdaptiveImageRecognizer</returns>
        public static AdaptiveImageRecognizer Load(string filename, int NumTemplatesPerGate)
        {
            AdaptiveImageRecognizer adaptive = Load(filename);

            adaptive.numTemplatesPerGate = NumTemplatesPerGate;
            return(adaptive);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Clears all templates from the adaptive image recognizer by deleting the saved file and reloading.
        /// </summary>
        /// <param name="air"></param>
        public override void reset()
        {
            File.Delete(AppDomain.CurrentDomain.BaseDirectory + myAdaptive);
            AdaptiveImageRecognizer air = LoadDefault();

            this._shapesToSymbols    = air._shapesToSymbols;
            this._templates          = air._templates;
            this._templateUsage      = air._templateUsage;
            this.numTemplatesPerGate = air.numTemplatesPerGate;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads a previously saved ImageRecognizer from the given filename,
        /// using the deserialization constructor
        /// </summary>
        /// <param name="filename">Filename which is the saved AdaptiveImageRecognizer</param>
        /// <returns>Re-instantiated AdaptiveImageRecognzier</returns>
        public new static AdaptiveImageRecognizer Load(string filename)
        {
            System.IO.Stream stream = System.IO.File.Open(filename, System.IO.FileMode.Open);
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            AdaptiveImageRecognizer image = (AdaptiveImageRecognizer)bformatter.Deserialize(stream);

            stream.Close();

            #if DEBUG
            Console.WriteLine("Adaptive image recognizer loaded.");
            #endif

            return(image);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Constructs a universal recognizer that using the specified
        /// recognizers and caching enabled or disabled.
        /// </summary>
        /// <param name="wireRecognizer">the recognizer to use on wires</param>
        /// <param name="textRecognizer">the recognizer to use on text</param>
        /// <param name="gateRecognizer">the recognizer to use on gates</param>
        /// <exception cref="ArgumentException.ArgumentException">Thrown if
        /// the provided recognizers cannot recognize what they are intended
        /// to (e.g., if the wireRecognizer reports that it cannot recognize
        /// wires).</exception>
        public UniversalRecognizer(
            Recognizer wireRecognizer = null,
            Recognizer textRecognizer = null,
            Recognizer gateRecognizer = null)
        {
            if (wireRecognizer == null)
            {
                wireRecognizer = new WireRecognizer();
            }
            if (textRecognizer == null)
            {
                textRecognizer = new TextRecognizer();
            }
            if (gateRecognizer == null)
            {
#if AIR_OFF
                gateRecognizer = new ImageRecognizer();
#else
                gateRecognizer = AdaptiveImageRecognizer.LoadDefault();
#endif
            }

            if (!wireRecognizer.canRecognize("Wire"))
            {
                throw new ArgumentException("The provided wire recognizer '" + wireRecognizer + "' cannot recognize wires!");
            }
            if (!textRecognizer.canRecognize("Text"))
            {
                throw new ArgumentException("The provided text recognizer '" + textRecognizer + "' cannot recognize text!");
            }
            if (!gateRecognizer.canRecognize("Gate"))
            {
                throw new ArgumentException("The provided gate recognizer '" + gateRecognizer + "' cannot recognize gates!");
            }

            _wireRecognizer = wireRecognizer;
            _textRecognizer = textRecognizer;
            _gateRecognizer = gateRecognizer;
        }