Пример #1
0
        public static Image DrawImageDetectionResult(MultiObjectLocalizationAndLabelingResult res, string image_url, List <string> Categories)
        {
            Image            originalImage = ImageUtilities.getImageFromURI(image_url);
            List <Rectangle> rectangles    = new List <Rectangle>();
            List <Color>     colors        = new List <Color>();
            List <string>    ids           = new List <string>();
            List <bool>      dashed        = new List <bool>();

            for (int j = 0; j < res.objects.Count; j++)
            {
                MultiObjectLocalizationAndLabelingResultSingleEntry box = res.objects[j];
                int       x      = box.boundingBox.tlx;
                int       y      = box.boundingBox.tly;
                int       width  = box.boundingBox.brx - box.boundingBox.tlx;
                int       height = box.boundingBox.bry - box.boundingBox.tly;
                Rectangle r      = new Rectangle(x, y, width, height);
                rectangles.Add(r);
                string category   = box.Category;
                int    colorIndex = Categories.IndexOf(category);
                colors.Add(DrawingBoxesAndLinesOnImages.Colors[colorIndex]);
                string id = j + "-" + category;
                ids.Add(id);
                dashed.Add(false);
            }
            Image imageWithBoxes = DrawingBoxesAndLinesOnImages.addRectanglesToImage(originalImage, rectangles, colors, ids, dashed);

            return(imageWithBoxes);
        }
Пример #2
0
        public static void SaveResultImagesLocally(List <SatyamResultsTableEntry> entries, string directoryName)
        {
            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

            directoryName = directoryName + "\\Raw";

            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }

            for (int i = 0; i < entries.Count; i++)
            {
                SatyamResultsTableEntry entry        = entries[i];
                SatyamResult            satyamResult = JSonUtils.ConvertJSonToObject <SatyamResult>(entry.ResultString);
                SatyamTask task = JSonUtils.ConvertJSonToObject <SatyamTask>(satyamResult.TaskParametersString);
                SatyamJob  job  = task.jobEntry;



                MultiObjectLocalizationAndLabelingResult res = JSonUtils.ConvertJSonToObject <MultiObjectLocalizationAndLabelingResult>(satyamResult.TaskResult);

                string   ofilename = URIUtilities.filenameFromURI(task.SatyamURI);
                string[] fields    = ofilename.Split('.');
                string   fileName  = fields[0];

                Image originalImage = ImageUtilities.getImageFromURI(task.SatyamURI);

                MultiObjectLocalizationAndLabelingSubmittedJob jobDefinition = JSonUtils.ConvertJSonToObject <MultiObjectLocalizationAndLabelingSubmittedJob>(job.JobParameters);

                Image imageWithBoundary = DrawingBoxesAndLinesOnImages.addLinesToImage(originalImage, jobDefinition.BoundaryLines, Color.Red, true);

                List <Rectangle> rectangles = new List <Rectangle>();
                List <Color>     colors     = new List <Color>();
                List <string>    ids        = new List <string>();
                List <bool>      dashed     = new List <bool>();
                for (int j = 0; j < res.objects.Count; j++)
                {
                    MultiObjectLocalizationAndLabelingResultSingleEntry box = res.objects[j];
                    int       x      = box.boundingBox.tlx;
                    int       y      = box.boundingBox.tly;
                    int       width  = box.boundingBox.brx - box.boundingBox.tlx;
                    int       height = box.boundingBox.bry - box.boundingBox.tly;
                    Rectangle r      = new Rectangle(x, y, width, height);
                    rectangles.Add(r);

                    string category   = box.Category;
                    int    colorIndex = jobDefinition.Categories.IndexOf(category);
                    colors.Add(DrawingBoxesAndLinesOnImages.Colors[colorIndex]);

                    string id = j + "-" + category;
                    ids.Add(id);

                    dashed.Add(false);
                }
                Image imageWithBoxesAndBoundary = DrawingBoxesAndLinesOnImages.addRectanglesToImage(imageWithBoundary, rectangles, colors, ids, dashed);

                fileName = fileName + "-Result";
                if (satyamResult.amazonInfo.AssignmentID != "")
                {
                    //fileName = fileName + "-" + satyamResult.amazonInfo.AssignmentID + "_" + entry.ID;
                    fileName = fileName + "-" + entry.ID + "_" + satyamResult.PrevResultID;
                }

                ImageUtilities.saveImage(imageWithBoxesAndBoundary, directoryName, fileName);
            }
        }