Exemplo n.º 1
0
        public void LearningTest()
        {
            MathTextBitmap bitmap =
                new MathTextBitmap(new FloatBitmap(5, 5), new Gdk.Point(0, 0));

            bitmap.ProcessImage(new List <BitmapProcesses.BitmapProcess>());

            CharacteristicTreeDatabase database =
                new CharacteristicTreeDatabase();

            MathSymbol aSymbol = new MathSymbol("a");
            MathSymbol bSymbol = new MathSymbol("b");

            database.Learn(bitmap, aSymbol);

            List <MathSymbol> symbols = database.Match(bitmap);

            bool a1Learned = symbols.Count == 1 &&
                             symbols[0] == aSymbol;

            bool a2Learned = true;

            a2Learned = database.Learn(bitmap, aSymbol);


            database.Learn(bitmap, bSymbol);
            symbols = database.Match(bitmap);

            bool b1Learned = symbols.Count == 2;

            Assert.IsTrue(a1Learned, "Fallo el aprender la primera a");
            Assert.IsFalse(a2Learned, "No se detecto el conflicto de la segunda a");
            Assert.IsTrue(b1Learned, "Fallo el aprender la b");
        }
        private void OnImagesIVSelectionChanged(object s, EventArgs a)
        {
            removeImageBtn.Sensitive = imagesIV.SelectedItems.Length > 0;

            TreeIter selectedIter;

            if (imagesIV.SelectedItems.Length > 0)
            {
                TreePath selectedImagePath = imagesIV.SelectedItems[0];

                imagesStore.GetIter(out selectedIter, selectedImagePath);

                Gdk.Pixbuf orig = (Gdk.Pixbuf)(imagesStore.GetValue(selectedIter, 1));

                mtb = new MathTextBitmap(orig);
                mtb.ProcessImage(database.Processes);

                imageAreaOriginal.Image  = orig;
                imageAreaProcessed.Image = mtb.LastProcessedImage.CreatePixbuf();
            }
            else
            {
                imageAreaOriginal.Image  = null;
                imageAreaProcessed.Image = null;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Con este metodo cramos un arbol de imagenes, de forma recursiva.
        /// Primero intentamos reconocer la imagen como un caracter, si no es
        /// posible, la intentamos segmentar. Si ninguno de estos procesos es
        /// posible, la imagen nopudo ser reconocida.
        /// </summary>
        /// <param name="node">
        /// El nodo donde esta la imagen sobre la que trabajaremos.
        /// </param>
        private void RecognizerTreeBuild(SegmentedNode node)
        {
            // Seleccionamos el nodo.

            NodeBeingProcessedInvoker(node);
            SuspendByNode();

            node.Select();

            while (node.ChildCount > 0)
            {
                node.RemoveChild((SegmentedNode)node[0]);
            }

            MathTextBitmap bitmap = node.MathTextBitmap;

            MessageLogSentInvoker("=======================================");
            MessageLogSentInvoker("Tratando la subimagen «{0}»",
                                  node.Name);

            // Lanzamos el reconocedor de caracteres para cada una de
            // las bases de datos.
            List <MathSymbol> associatedSymbols = new List <MathSymbol>();

            if (searchDatabase)
            {
                foreach (MathTextDatabase database in databases)
                {
                    MessageLogSentInvoker("---------- «{0}» ------------",
                                          database.ShortDescription);


                    bitmap.ProcessImage(database.Processes);
                    BitmapProcessedByDatabaseInvoker(bitmap);

                    // Añadimos los caracteres reconocidos por la base de datos
                    foreach (MathSymbol symbol in database.Recognize(bitmap))
                    {
                        if (!associatedSymbols.Contains(symbol))
                        {
                            // Solo añadimos si no esta ya el simbolo.
                            associatedSymbols.Add(symbol);
                        }
                    }
                }
            }


            // We associate all symbols to the node, so we can postargate
            // the decission step.
            node.Symbols = associatedSymbols;

            //Si no hemos reconocido nada, pues intentaremos segmentar el caracter.
            if (associatedSymbols.Count == 0)
            {
                if (searchDatabase)
                {
                    MessageLogSentInvoker("La imagen no pudo ser reconocida como un "
                                          + "simbolo por la base de datos, se tratará de "
                                          + "segmentar");
                }
                else
                {
                    MessageLogSentInvoker("Se procede directamente a segmentar la imagen");
                    this.SearchDatabase = true;
                }

                List <MathTextBitmap> children = CreateChildren(bitmap);

                if (children.Count > 1)
                {
                    MessageLogSentInvoker("La imagen se ha segmentado correctamente");

                    //Si solo conseguimos un hijo, es la propia imagen, asi que nada

                    List <SegmentedNode> nodes = new List <SegmentedNode>();

                    foreach (MathTextBitmap child in children)
                    {
                        SegmentedNode childNode = new SegmentedNode(child, node.View);
                        node.AddSegmentedChild(childNode);
                        nodes.Add(childNode);
                    }

                    foreach (SegmentedNode childNode in nodes)
                    {
                        RecognizerTreeBuild(childNode);
                    }
                }
                else
                {
                    MessageLogSentInvoker("La imagen no pudo ser segmentada, el "
                                          + "símbolo queda sin reconocer");
                }
            }
            else
            {
                // We prepare the string.
                string text = "";
                foreach (MathSymbol s in associatedSymbols)
                {
                    text += String.Format("«{0}», ", s.Text);
                }

                text = text.TrimEnd(',', ' ');
                MessageLogSentInvoker("Símbolo reconocido por la base de datos como {0}.",
                                      text);
            }
        }