Ejemplo n.º 1
0
        private static async Task <List <Img> > GetImagesFromDataset(Project project, string resourcesPath, string imagesDataset, CloudFileShare share = null, string mode = "url")
        {
            List <Img> images = new List <Img>();

            IEnumerable <ICsvLine> dataset = null;

            try
            {
                string path = Path.GetFullPath(resourcesPath + imagesDataset);
                Console.WriteLine($"\nImages dataset: '{path}'");
                dataset = LoadDataset(path);
            }
            catch (Exception e)
            {
                Console.WriteLine($"\n{e.GetType().Name}: Error loading image dataset.");
            }

            if (dataset != null)
            {
                try
                {
                    foreach (var line in dataset)
                    {
                        Img img = null;
                        if (mode == "url")
                        {
                            if (share == null)
                            {
                                Console.WriteLine($"\nNo file share was provided, upload images using files instead.");
                            }
                            else
                            {
                                img = await GetImageFromURL(project, line, share);
                            }
                        }
                        else
                        {
                            img = await GetImageFromFile(project, line, resourcesPath);
                        }
                        images.Add(img);
                    }
                    Console.WriteLine($"\nImage dataset created: {images.Count} images found.");
                }
                catch (Exception e)
                {
                    Console.WriteLine($"\n{e.GetType().Name}: Error getting images.");
                }
            }


            return(images);
        }
Ejemplo n.º 2
0
        private static async Task <Img> GetImageFromFile(Project project, ICsvLine line, string resourcesPath)
        {
            Img    img     = new Img();
            string imgpath = "";
            string tags    = "";

            try
            {
                imgpath      = line["sourcefile"];
                img.filepath = Path.GetFullPath(resourcesPath + "/trainingImages/" + imgpath);
                tags         = line["tags"];
            }
            catch (Exception e)
            {
                Console.WriteLine($"\n{e.GetType().Name}: Could not get source file name and tags from csv file.");
                throw;
            }

            string[] tagsList = tags.Split(',');

            foreach (string t in tagsList)
            {
                try
                {
                    Tag tag = await GetTag(project, t);

                    img.tags.Add(tag);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"\n{e.GetType().Name}: Could not get tag from project.");
                    throw;
                }
            }

            return(img);
        }
Ejemplo n.º 3
0
        private static async Task <Img> GetImageFromURL(Project project, ICsvLine line, CloudFileShare share)
        {
            Img    img  = new Img();
            string url  = "";
            string tags = "";

            try
            {
                url     = line["sourcefile"];
                img.url = AzureStorageHelpers.GetFileURL(url, share);
                tags    = line["tags"];
            }
            catch (Exception e)
            {
                Console.WriteLine($"\n{e.GetType().Name}: Could not get source file name and tags from csv file.");
                throw;
            }

            string[] tagsList = tags.Split(',');

            foreach (string t in tagsList)
            {
                try
                {
                    Tag tag = await GetTag(project, t);

                    img.tags.Add(tag);
                }
                catch (Exception e)
                {
                    Console.WriteLine($"\n{e.GetType().Name}: Could not get tag from project.");
                    throw;
                }
            }

            return(img);
        }