Exemple #1
0
        public List <SPositionObjetDansImage> positionnerObjetsDansImage(NDArray[] resultArr)
        {
            if (resultArr == null || resultArr.Length == 0)
            {
                return(null);
            }

            PbtxtItems pbTxtItems = PbtxtParser.ParsePbtxtFile(labelFile);
            List <SPositionObjetDansImage> lPositionObjetDansImages = new List <SPositionObjetDansImage>();
            SPositionObjetDansImage        sPositionObjetDansImage  = new SPositionObjetDansImage();

            float[] scores = resultArr[2].Data <float>();

            for (int i = 0; i < scores.Length; i++)
            {
                float score = scores[i];

                if (score > MIN_SCORE)
                {
                    float[] boxes  = resultArr[1].Data <float>();
                    float   top    = boxes[i * 4] * this.bitmapOutput.Height;
                    float   left   = boxes[i * 4 + 1] * this.bitmapOutput.Width;
                    float   bottom = boxes[i * 4 + 2] * this.bitmapOutput.Height;
                    float   right  = boxes[i * 4 + 3] * this.bitmapOutput.Width;

                    Rectangle rect = new Rectangle()
                    {
                        X      = (int)left,
                        Y      = (int)top,
                        Width  = (int)(right - left),
                        Height = (int)(bottom - top)
                    };

                    //Définition du centre de l'objet détecté
                    rect.X      = rect.X + (rect.Width / 2);
                    rect.Y      = rect.Y + (rect.Height / 2);
                    rect.Width  = 1;
                    rect.Height = 1;

                    float[] ids = resultArr[3].Data <float>();

                    string name = pbTxtItems.items.Where(w => w.id == (int)ids[i]).Select(s => s.display_name).FirstOrDefault();

                    //Stockage des valeurs: nom, positionX et positionY de l'objet (les positions sont en pixel)
                    sPositionObjetDansImage.libelle    = name;
                    sPositionObjetDansImage.position.x = rect.X;
                    sPositionObjetDansImage.position.y = rect.Y;

                    lPositionObjetDansImages.Add(sPositionObjetDansImage);
                }
            }

            return(lPositionObjetDansImages);
        }
Exemple #2
0
        public void GenererImageSortie(NDArray[] resultArr, string filename = @"output.jpg")
        {
            if (resultArr != null)
            {
                this.SetImageSortie(filename);
                PbtxtItems pbTxtItems = PbtxtParser.ParsePbtxtFile(labelFile);
                float[]    scores     = resultArr[2].Data <float>();
                this.imageSortie = filename;

                for (int i = 0; i < scores.Length; i++)
                {
                    float score = scores[i];

                    if (score > MIN_SCORE)
                    {
                        float[] boxes  = resultArr[1].Data <float>();
                        float   top    = boxes[i * 4] * this.bitmapOutput.Height;
                        float   left   = boxes[i * 4 + 1] * this.bitmapOutput.Width;
                        float   bottom = boxes[i * 4 + 2] * this.bitmapOutput.Height;
                        float   right  = boxes[i * 4 + 3] * this.bitmapOutput.Width;

                        Rectangle rect = new Rectangle()
                        {
                            X      = (int)left,
                            Y      = (int)top,
                            Width  = (int)(right - left),
                            Height = (int)(bottom - top)
                        };

                        float[] ids  = resultArr[3].Data <float>();
                        string  name = pbTxtItems.items.Where(w => w.id == (int)ids[i]).Select(s => s.display_name).FirstOrDefault();
                        DessinerObjetIdentifier(this.bitmapOutput, rect, score, name);
                    }
                }

                this.bitmapOutput.Save(this.imageSortie);
                DirectoryInfo dir = new DirectoryInfo(Directory.GetCurrentDirectory() + @"\" + Path.GetDirectoryName(this.imageSortie));
                Console.WriteLine(DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + " | " + $"Emplacement de l'image de sortie: {dir.FullName + @"\" + Path.GetFileName(this.imageSortie)}");
            }
            else
            {
                Console.WriteLine("+-------------------------------------------------------------------------------------------------+");
                Console.WriteLine("| " + DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + " | Méthode: \"GenererImageSortie(NDArray[] resultArr, string filename = @\"output.jpg\")\"  |");
                Console.WriteLine("| Impossible de générer une image de sortie car la variable \"resultArr\" vaut: null.               |");
                Console.WriteLine("+-------------------------------------------------------------------------------------------------+");
                Console.WriteLine(" ");
                Console.WriteLine(DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + " | " + $"Emplacement de l'image de sortie: {this.imageSortie}");
            }
        }
Exemple #3
0
        public void afficherRenduDetectionConsole(NDArray[] resultArr)
        {
            if (resultArr != null)
            {
                PbtxtItems pbTxtItems = PbtxtParser.ParsePbtxtFile(labelFile);

                float[] scores = resultArr[2].Data <float>();

                Console.WriteLine("");
                Console.WriteLine("+-----------Detection----------+");
                Console.WriteLine("");

                for (int i = 0; i < scores.Length; i++)
                {
                    float score = scores[i];
                    if (score > MIN_SCORE)
                    {
                        float[] boxes  = resultArr[1].Data <float>();
                        float   top    = boxes[i * 4] * this.bitmapOutput.Height;
                        float   left   = boxes[i * 4 + 1] * this.bitmapOutput.Width;
                        float   bottom = boxes[i * 4 + 2] * this.bitmapOutput.Height;
                        float   right  = boxes[i * 4 + 3] * this.bitmapOutput.Width;

                        Rectangle rect = new Rectangle()
                        {
                            X      = (int)left,
                            Y      = (int)top,
                            Width  = (int)(right - left),
                            Height = (int)(bottom - top)
                        };

                        float[] ids = resultArr[3].Data <float>();

                        string name = pbTxtItems.items.Where(w => w.id == (int)ids[i]).Select(s => s.display_name).FirstOrDefault();
                        Console.WriteLine("Objet: " + name + " " + score + " dans la zone: " + rect);
                    }
                }
            }
            else
            {
                Console.WriteLine("+---------------------------------------------------------------------------+");
                Console.WriteLine("| " + DateTime.Now.ToString("HH:mm:ss", System.Globalization.DateTimeFormatInfo.InvariantInfo) + " | Méthode: \"afficherRenduDetectionConsole(NDArray[] resultArr)\"");
                Console.WriteLine("| Aucun affichage console possible car la variable \"resultArr\" vaut: null.");
                Console.WriteLine("+---------------------------------------------------------------------------+");
                Console.WriteLine(" ");
            }
        }