public ResultType IsRelevant(ClsPrediction pred, bool IsNew, out bool IgnoreMask, string DbgDetail = "")
 {
     return(IsRelevant(new List <ClsPrediction>()
     {
         pred
     }, IsNew, out IgnoreMask, DbgDetail));
 }
示例#2
0
        private async void FormatRow(object Sender, BrightIdeasSoftware.FormatRowEventArgs e)
        {
            try
            {
                ClsPrediction OP = (ClsPrediction)e.Model;

                // If SPI IsNot Nothing Then
                if (OP.Result == ResultType.Relevant)
                {
                    e.Item.ForeColor = Color.DarkGreen;   //AppSettings.Settings.RectRelevantColor;
                }
                else if (OP.Result == ResultType.DynamicMasked || OP.Result == ResultType.ImageMasked || OP.Result == ResultType.StaticMasked)
                {
                    e.Item.ForeColor = AppSettings.Settings.RectMaskedColor;
                }
                else if (OP.Result == ResultType.Error)
                {
                    e.Item.ForeColor = Color.Black;
                    e.Item.BackColor = Color.Red;
                }
                else
                {
                    e.Item.ForeColor = AppSettings.Settings.RectIrrelevantColor;
                }
            }



            catch (Exception)
            {
            }
            finally
            {
            }
        }
        public ResultType IsRelevant(string Label, out bool IgnoreMask, string DbgDetail = "")
        {
            ClsPrediction pred = new ClsPrediction();

            pred.Label = Label;
            return(IsRelevant(new List <ClsPrediction>()
            {
                pred
            }, true, out IgnoreMask, DbgDetail));
        }
示例#4
0
        //public ResultType IsRelevantObject(ClsPrediction pred)
        //{
        //    if (Global.IsInList(pred.Label, this.triggering_objects_as_string, TrueIfEmpty: false) || Global.IsInList(pred.Label, this.additional_triggering_objects_as_string, TrueIfEmpty: false))
        //        return ResultType.Relevant;
        //    else
        //        return ResultType.UnwantedObject;

        //}
        public ResultType IsRelevantSize(ClsPrediction pred)
        {
            ResultType ret = ResultType.Relevant;

            if (pred.RectWidth == 0 || pred.RectHeight == 0 || pred.ImageHeight == 0 || pred.ImageWidth == 0)
            {
                return(ResultType.Unknown);
            }

            //public int PredSizeMinPercentOfImage = 1;   //prediction must be at least this % of the image
            //public int PredSizeMaxPercentOfImage = 95;
            //public int PredSizeMinHeight = 0;
            //public int PredSizeMinWidth = 0;
            //public int PredSizeMaxHeight = 0;
            //public int PredSizeMaxWidth = 0;

            if (this.PredSizeMinPercentOfImage > 0 || this.PredSizeMaxPercentOfImage > 0)
            {
                if (pred.PercentOfImage < this.PredSizeMinPercentOfImage)
                {
                    ret = ResultType.TooSmallPercent;
                }
                else if (this.PredSizeMaxPercentOfImage > 0 && pred.PercentOfImage > this.PredSizeMaxPercentOfImage)
                {
                    ret = ResultType.TooLargePercent;
                }
            }

            if (ret == ResultType.Relevant)
            {
                if (pred.RectWidth < this.PredSizeMinWidth)
                {
                    ret = ResultType.TooSmallWidth;
                }
                else if (pred.RectHeight < this.PredSizeMinHeight)
                {
                    ret = ResultType.TooSmallHeight;
                }
                else if (this.PredSizeMaxWidth > 0 && pred.RectWidth > this.PredSizeMaxWidth)
                {
                    ret = ResultType.TooLargeWidth;
                }
                else if (this.PredSizeMaxHeight > 0 && pred.RectHeight > this.PredSizeMaxHeight)
                {
                    ret = ResultType.TooLargeHeight;
                }
            }

            return(ret);
        }
示例#5
0
        private void showObject(PaintEventArgs e, ClsPrediction pred)
        {
            try
            {
                if ((this.pictureBox1 != null) && (this.pictureBox1.Image != null))
                {
                    e.Graphics.Transform = transform;

                    System.Drawing.Color color = new System.Drawing.Color();
                    int BorderWidth            = AppSettings.Settings.RectBorderWidth
                    ;

                    if (pred.Result == ResultType.Relevant)
                    {
                        color = System.Drawing.Color.FromArgb(AppSettings.Settings.RectRelevantColorAlpha, AppSettings.Settings.RectRelevantColor);
                    }
                    else if (pred.Result == ResultType.DynamicMasked || pred.Result == ResultType.ImageMasked || pred.Result == ResultType.StaticMasked)
                    {
                        color = System.Drawing.Color.FromArgb(AppSettings.Settings.RectMaskedColorAlpha, AppSettings.Settings.RectMaskedColor);
                    }
                    else
                    {
                        color = System.Drawing.Color.FromArgb(AppSettings.Settings.RectIrrelevantColorAlpha, AppSettings.Settings.RectIrrelevantColor);
                    }

                    //1. get the padding between the image and the picturebox border

                    //get dimensions of the image and the picturebox
                    float imgWidth  = this.pictureBox1.Image.Width;
                    float imgHeight = this.pictureBox1.Image.Height;
                    float boxWidth  = this.pictureBox1.Width;
                    float boxHeight = this.pictureBox1.Height;
                    float clnWidth  = this.pictureBox1.ClientSize.Width;
                    float clnHeight = this.pictureBox1.ClientSize.Height;
                    float rctWidth  = this.pictureBox1.ClientRectangle.Width;
                    float rctHeight = this.pictureBox1.ClientRectangle.Height;

                    //these variables store the padding between image border and picturebox border
                    int absX = 0;
                    int absY = 0;

                    //because the sizemode of the picturebox is set to 'zoom', the image is scaled down
                    float scale = 1;


                    //Comparing the aspect ratio of both the control and the image itself.
                    if (imgWidth / imgHeight > boxWidth / boxHeight)      //if the image is p.e. 16:9 and the picturebox is 4:3
                    {
                        scale = boxWidth / imgWidth;                      //get scale factor
                        absY  = (int)(boxHeight - scale * imgHeight) / 2; //padding on top and below the image
                    }
                    else //if the image is p.e. 4:3 and the picturebox is widescreen 16:9
                    {
                        scale = boxHeight / imgHeight;                  //get scale factor
                        absX  = (int)(boxWidth - scale * imgWidth) / 2; //padding left and right of the image
                    }

                    //2. inputted position values are for the original image size. As the image is probably smaller in the picturebox, the positions must be adapted.
                    int xmin = (int)(scale * pred.XMin) + absX;
                    int xmax = (int)(scale * pred.XMax) + absX;
                    int ymin = (int)(scale * pred.YMin) + absY;
                    int ymax = (int)(scale * pred.YMax) + absY;

                    int sclWidth  = xmax - xmin;
                    int sclHeight = ymax - ymin;

                    int sclxmax = (int)boxWidth - (absX * 2);
                    int sclymax = (int)boxHeight - (absY * 2);
                    int sclxmin = absX;
                    int sclymin = absY;

                    //3. paint rectangle
                    System.Drawing.Rectangle rect = new System.Drawing.Rectangle(xmin,
                                                                                 ymin,
                                                                                 sclWidth,
                                                                                 sclHeight);

                    pictureBox2.Image = cropImage(OriginalBMP, pred.GetRectangle());

                    using (Pen pen = new Pen(color, BorderWidth))
                    {
                        e.Graphics.DrawRectangle(pen, rect); //draw rectangle
                    }


                    ///testing=================================================
                    //3. paint rectangle
                    //rect = new System.Drawing.Rectangle(absX + 5,
                    //                                    absY + 5,
                    //                                    sclxmax - 10,
                    //                                    sclymax - 10);

                    //using (Pen pen = new Pen(Color.Red, BorderWidth))
                    //{
                    //    e.Graphics.DrawRectangle(pen, rect); //draw rectangle
                    //}
                    ///testing=================================================

                    //we need this since people can change the border width in the json file
                    int halfbrd = BorderWidth / 2;


                    Brush brush = new SolidBrush(color);                                                                                                                                         //sets background rectangle color

                    System.Drawing.SizeF TextSize = e.Graphics.MeasureString(pred.ToString(), new Font(AppSettings.Settings.RectDetectionTextFont, AppSettings.Settings.RectDetectionTextSize)); //finds size of text to draw the background rectangle


                    //object name text below rectangle

                    int x = xmin - halfbrd;
                    int y = ymax + halfbrd;

                    //just for debugging:
                    //int timgWidth = (int)imgWidth;
                    //int tboxWidth = (int)boxWidth;
                    //int tsclWidth = (int)sclWidth;

                    //int timgHeight = (int)imgHeight;
                    //int tboxHeight = (int)boxHeight;
                    //int tsclHeight = (int)sclHeight;


                    //adjust the x / width label so it doesnt go off screen
                    int EndX = x + (int)TextSize.Width;
                    if (EndX > sclxmax)
                    {
                        //int diffx = x - sclxmax;
                        x = xmax - (int)TextSize.Width + halfbrd;
                    }

                    if (x < sclxmin)
                    {
                        x = sclxmin;
                    }

                    if (x < 0)
                    {
                        x = 0;
                    }

                    //adjust the y / height label so it doesnt go off screen
                    int EndY = y + (int)TextSize.Height;
                    if (EndY > sclymax)
                    {
                        //float diffy = EndY - sclymax;
                        y = ymax - (int)TextSize.Height - halfbrd;
                    }

                    if (y < 0)
                    {
                        y = 0;
                    }


                    rect = new System.Drawing.Rectangle(x,
                                                        y,
                                                        (int)boxWidth,
                                                        (int)boxHeight); //sets bounding box for drawn text


                    e.Graphics.FillRectangle(brush,
                                             x,
                                             y,
                                             TextSize.Width,
                                             TextSize.Height);                                                                                                                     //draw grey background rectangle for detection text

                    e.Graphics.DrawString(pred.ToString(), new Font(AppSettings.Settings.RectDetectionTextFont, AppSettings.Settings.RectDetectionTextSize), Brushes.Black, rect); //draw detection text
                }
            }
            catch (Exception ex)
            {
                Log("Error: " + ex.Msg());
            }
        }