Exemplo n.º 1
0
        public static Image drawRectangle(PictureBox image, Singularity sing)
        {
            if (image.Image == null)
            {
                return(null);
            }

            Bitmap   img     = new Bitmap(image.Image);
            Graphics graphic = Graphics.FromImage(img);

            Rectangle rect = GraphicsUtils.getRectFromSing(sing, img.Width, img.Height);

            graphic.DrawRectangle(GraphicsUtils.getInstance().getPen(sing), rect);

            image.Image = img;

            return(((Bitmap)_currentImage).Clone(rect, img.PixelFormat));
        }
Exemplo n.º 2
0
        public static SortedDictionary <String, List <GroundTruth> > buildDataFromFile(string pathFile, string pathDataset)
        {
            string[]    data    = File.ReadAllLines(pathFile);
            string[]    txt     = null;
            string      imgName = null;
            string      dbName  = new DirectoryInfo(pathDataset).Name;
            GroundTruth gt      = null;
            SortedDictionary <String, List <GroundTruth> > groundTruth = new SortedDictionary <string, List <GroundTruth> >();

            MenuService menuService = new MenuService();

            for (int i = 0; i < data.Length; i++)
            {
                if (data[i].CompareTo("") == 0)
                {
                    continue;
                }

                txt = data[i].Split(FileUtils._token);

                if (txt.Length == 1)
                {
                    imgName = txt[0].Trim();


                    i++;

                    while (i < data.Length && data[i].CompareTo("") != 0)
                    {
                        txt = data[i].Split(FileUtils._token);
                        gt  = new GroundTruth();

                        gt._sing._x     = int.Parse(txt[0]);
                        gt._sing._y     = int.Parse(txt[1]);
                        gt._sing._type  = Singularity.stringToSingType(txt[2].Trim());
                        gt._datasetName = dbName;
                        gt._imageName   = imgName;


                        string[] file        = imgName.Split('.');
                        string   rectImgName = string.Format("{0}_{1}_{2}_{3}.{4}", file[0], gt._sing._type.ToString(), gt._sing._x, gt._sing._y, file[1]);
                        string   p           = Path.Combine(pathDataset, gt._sing._type.ToString(), rectImgName);
                        if (File.Exists(p))
                        {
                            gt._sing._image = new Bitmap(p);
                        }
                        else
                        {
                            p = p = Path.Combine(pathDataset, imgName);
                            Bitmap    b    = new Bitmap(p);
                            Rectangle rect = GraphicsUtils.getRectFromSing(gt._sing, b.Width, b.Height);
                            gt._sing._image = b.Clone(rect, b.PixelFormat);
                        }

                        menuService.addGroundTruth(groundTruth, imgName, gt);

                        i++;
                    }
                }
            }

            return(groundTruth);
        }