Ejemplo n.º 1
0
        /// <summary>
        /// Creates training data for the entire symbol with no context.
        /// </summary>
        /// <param name="filename">Filename of the current sketch.</param>
        /// <param name="start">Number of the file.</param>
        private void noContext(string filename, string start)
        {
            string path = Path.GetFullPath(filename);
            string dir  = Path.GetDirectoryName(path);

            List <Substroke> subs = new List <Substroke>();

            // Go through all the shapes and add all the substrokes to a list except if the shape is context
            foreach (Shape shape in this.sketch.Shapes)
            {
                if (shape.XmlAttrs.Type != "context")
                {
                    foreach (Substroke sub in shape.SubstrokesL)
                    {
                        subs.Add(sub);
                    }
                }
            }

            // Create the windowed image (which does not actually window anything since all the substrokes
            // are keys/not only neighbors)
            WindowedImage image = new WindowedImage(32, 32);

            image.CreateImage(subs, subs, CropMethod.DISTANCE);

            // Write the training file
            write(image.Cropped.SubStrokes, dir + "\\" + start + ".non.xml");

            //image.DI.writeToBitmap(dir + "\\" + start, "non.bmp");
            //image.DI.writeToFile(dir + "\\" + start + ".non.imat");
            //image.writeToBitmap(dir + "\\" + start + ".non.bmp");
            //image.writeToFile(dir + "\\" + start + ".non.imat").Close();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates training data for the entire symbol with cropped context.
        /// </summary>
        /// <param name="neighborhood">The neighborhood mapping of substrokes to neighboring substrokes of the sketch.</param>
        /// <param name="filename">The filename of the current sketch.</param>
        /// <param name="start">Number of the file.</param>
        private void croppedContextForSymbol(Neighborhood neighborhood, string filename, string start)
        {
            string path = Path.GetFullPath(filename);
            string dir  = Path.GetDirectoryName(path);

            // Get all of the shapes that are not context
            List <Shape> nonContext = new List <Shape>();

            foreach (Shape shape in this.sketch.Shapes)
            {
                if (shape.XmlAttrs.Type != "context")
                {
                    nonContext.Add(shape);
                }
            }

            // Get all of the neighbors of the non-context shapes (which may include context)
            // and make sure only to add each substroke once
            List <Substroke> neighbors = new List <Substroke>();
            List <Substroke> keys      = new List <Substroke>();

            foreach (Shape shape in nonContext)
            {
                foreach (Substroke sub in shape.SubstrokesL)
                {
                    keys.Add(sub);
                    foreach (Substroke neighbor in neighborhood.Graph[sub.XmlAttrs.Id.Value])
                    {
                        if (!neighbors.Contains(neighbor))
                        {
                            neighbors.Add(neighbor);
                        }
                    }
                }
            }

            // Create a windowed image that will include cropped context
            WindowedImage image = new WindowedImage(32, 32);

            image.CreateImage(keys, neighbors, CropMethod.DISTANCE);

            // Write the training file
            write(image.Cropped.SubStrokes, dir + "\\" + start + ".con.xml");

            //image.DI.writeToBitmap(dir + "\\" + start, "con.bmp");
            //image.DI.writeToFile(dir + "\\" + start + ".con.imat");
            //image.writeToBitmap(dir + "\\" + start + ".con.bmp");
            //image.writeToFile(dir + "\\" + start + ".con.imat").Close();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create training data for a shape with its cropped context.
        /// </summary>
        /// <param name="neighborhood">The neighborhood mapping of substrokes to neighboring substrokes of the sketch.</param>
        /// <param name="filename">Filename of the current sketch.</param>
        /// <param name="start">Number of the file.</param>
        /// <param name="userID">User ID (usually four numbers in the filename)</param>
        private void croppedContextForShape(Neighborhood neighborhood, string filename, string start, string userID)
        {
            Sketch.Sketch croppedContextSketch = new Sketch.Sketch(this.sketch);
            string        path = Path.GetFullPath(filename);
            string        dir  = Path.GetDirectoryName(path);

            // Go through every shape that is not context and write training data for each shape individually
            foreach (Shape shape in this.sketch.Shapes)
            {
                if (shape.XmlAttrs.Type != "context")
                {
                    // Get all of the neighbors of the shape
                    List <Substroke> neighbors = new List <Substroke>();
                    foreach (Substroke sub in shape.Substrokes)
                    {
                        foreach (Substroke neighbor in neighborhood.Graph[sub.XmlAttrs.Id.Value])
                        {
                            if (!neighbors.Contains(neighbor))
                            {
                                neighbors.Add(neighbor);
                            }
                        }
                    }

                    // Create new directory for the shape type if it does not exist
                    string newDirectory = dir + "\\" + shape.XmlAttrs.Type;
                    if (!Directory.Exists(newDirectory))
                    {
                        Directory.CreateDirectory(newDirectory);
                    }

                    // Create new directory for the userID if it does not exist
                    string userDirectory = newDirectory + "\\" + userID;
                    if (!Directory.Exists(userDirectory))
                    {
                        Directory.CreateDirectory(userDirectory);
                    }

                    // Create the windowed image of the shape and its context
                    WindowedImage image = new WindowedImage(32, 32);
                    image.CreateImage(shape.SubstrokesL, neighbors, CropMethod.DISTANCE);

                    // Write the training file
                    write(image.Cropped.SubStrokes, userDirectory + "\\" + shape.XmlAttrs.Type + "." + start + ".con.xml");

                    //image.DI.writeToBitmap(userDirectory + "\\" + start + "." + shape.XmlAttrs.Type, "con.bmp");
                    //image.DI.writeToFile(userDirectory + "\\" + start + "." + shape.XmlAttrs.Type + ".con.imat");
                    //image.writeToBitmap(userDirectory + "\\" + start + "." + shape.XmlAttrs.Type + ".con.bmp");
                    //image.writeToFile(userDirectory + "\\" + start + "." + shape.XmlAttrs.Type + ".con.imat").Close();

                    // Create the windowed image of the shape without context
                    image = new WindowedImage(32, 32);
                    image.CreateImage(shape.SubstrokesL, shape.SubstrokesL, CropMethod.DISTANCE);

                    // Write the training file
                    write(image.Cropped.SubStrokes, userDirectory + "\\" + shape.XmlAttrs.Type + "." + start + ".non.xml");

                    //image.DI.writeToBitmap(userDirectory + "\\" + start + "." + shape.XmlAttrs.Type, "non.bmp");
                    //image.DI.writeToFile(userDirectory + "\\" + start + "." + shape.XmlAttrs.Type + ".non.imat");
                    //image.writeToBitmap(userDirectory + "\\" + start + "." + shape.XmlAttrs.Type + ".non.bmp");
                    //image.writeToFile(userDirectory + "\\" + start + "." + shape.XmlAttrs.Type + ".non.imat").Close();
                }
            }
        }