Beispiel #1
0
        private void pictureEdit1_Paint(object sender, PaintEventArgs e)
        {
            try
            {
                Pen pen = new Pen(Color.Red, 1);
                pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                if (drawing)
                {
                    e.Graphics.DrawRectangle(pen, GetRectangle());
                }
                using (Bitmap bitmap = (Bitmap)Bitmap.FromFile(mTargetFileName))
                {
                    mPictureWidth  = (double)bitmap.Width;
                    mPictureHeight = (double)bitmap.Height;
                    int nIndex = nSelectedTarget;
                    //if (nIndex >= 0)
                    {
                        //Paint Vehicle Body Area
                        if (mResultInfoList.Count > 0)
                        {
                            for (int i = 0; i < mResultInfoList.Count; ++i)
                            {
                                TIEVision.COMMON.HOBJ.CvRect_t body = mResultInfoList[i].info.rect;
                                int       _x       = body.x;
                                int       _y       = body.y;
                                int       _h       = body.height;
                                int       _w       = body.width;
                                Rectangle bodyRect = new Rectangle(new Point(_x, _y), new Size(_w, _h));
                                Pen       penBlue  = new Pen(Color.FromArgb(0xff, Color.LimeGreen), 2);
                                if (i == nIndex)
                                {
                                    penBlue           = new Pen(Color.Red, 2);
                                    penBlue.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;

                                    //pick rectangle average color
                                    //bodyRect.Inflate(-bodyRect.Width / 4, -bodyRect.Height / 4);
                                    cropBmp = bitmap.Clone(bodyRect, bitmap.PixelFormat);
                                }
                                else
                                {
                                    penBlue.DashStyle = System.Drawing.Drawing2D.DashStyle.DashDot;
                                }
                                e.Graphics.DrawRectangle(penBlue, PicToScreen(new Rectangle(new Point(_x, _y), new Size(_w, _h))));
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #2
0
        private void pictureEdit1_MouseUp(object sender, MouseEventArgs e)
        {
            if (drawing)
            {
                drawing = false;
                this.pictureEdit1.Cursor = Cursors.Default;
                int nSelectIndex = -1;
                var rect         = GetRectangle();
                for (int nIndex = 0; nIndex < mResultInfoList.Count; nIndex++)
                {
                    TIEVision.COMMON.HOBJ.CvRect_t body = mResultInfoList[nIndex].info.rect;
                    int _x = body.x;
                    int _y = body.y;
                    int _h = body.height;
                    int _w = body.width;
                    mListCustomBodyRec.Add(new Rectangle(new Point(_x, _y), new Size(_w, _h)));


                    Rectangle bodyRect       = new Rectangle(new Point(_x, _y), new Size(_w, _h));
                    Rectangle overlappedRect = Rectangle.Empty;

                    Rectangle custRect = ScreenToPic(rect);
                    overlappedRect = Rectangle.Intersect(bodyRect, custRect);
                    if (!overlappedRect.IsEmpty)
                    {
                        double interSectPercent = Math.Round((double)(overlappedRect.Width * overlappedRect.Height) / (bodyRect.Width * bodyRect.Height), 2);
                        int    interSect        = Convert.ToInt32(interSectPercent * 100);
                        if (interSect > 60)
                        {
                            nSelectIndex = nIndex;
                        }
                        Console.WriteLine("重合度:" + interSect + " nIndex :" + nIndex);
                    }
                }
                nSelectedTarget = nSelectIndex;
            }
        }