コード例 #1
0
        public void CalulateAsync()
        {
            Stopwatch.Start();
            this.IsCalulating = true;

            //Calulate

            // Lets first get a cube to expand
            Vector2Int cubePosition = GetFirstWorkableCubePosition();

            if (cubePosition == -Vector2Int.One)
            {
                //whopsies, we got a lil poopie here, no cubes where found!
                MessageBox.Show("No Workable cubes found! Make sure you have generated them first");
                Stop();
                return;
            }
            ;

            while (cubePosition != -Vector2Int.One)
            {
                cubePosition = GetFirstWorkableCubePosition();
                var rect = new RectangleInt(cubePosition, cubePosition);
                rect = ExpandRectangle(rect);
                Rectangles.Add(rect);
            }



            // okay, we now have a cube, lets start a rectangle and expand it


            Stop();
        }
コード例 #2
0
        void SetFrom(ShapeCollectionSave shapeCollectionSave)
        {
            Clear();

            foreach (var saveObject in shapeCollectionSave.AxisAlignedRectangleSaves)
            {
                var runtime = saveObject.ToAxisAlignedRectangle();

                var vm = new AxisAlignedRectangleViewModel(runtime);

                Rectangles.Add(vm);
            }

            foreach (var saveObject in shapeCollectionSave.CircleSaves)
            {
                var runtime = saveObject.ToCircle();

                var vm = new CircleViewModel(runtime);

                Circles.Add(vm);
            }

            foreach (var saveObject in shapeCollectionSave.PolygonSaves)
            {
                var runtime = saveObject.ToPolygon();

                var vm = new PolygonViewModel(runtime);

                Polygons.Add(vm);
            }
        }
コード例 #3
0
ファイル: DrawRectangles.cs プロジェクト: sanchezzz41/MyPaint
        public void Draw(Point point1, Point point2)
        {
            var rectangle = Check(point1, point2);

            Graphics.DrawRectangle(Pen, rectangle);
            Rectangles.Add(rectangle, Pen.Color);
        }
コード例 #4
0
ファイル: Film.cs プロジェクト: zanxueyan/StackBuilder
 public void AddRectangle(FilmRectangle rect)
 {
     rect.Color        = Color;
     rect.HatchSpacing = HatchSpacing;
     rect.HatchAngle   = HatchAngle;
     Rectangles.Add(rect);
 }
コード例 #5
0
        private void Fill()
        {
            while (true)
            {
                var rect = Rectangles.FirstOrDefault(x => !x.Completed);

                if (rect == null)
                {
                    return;
                }

                var others = Rectangles.Where(x => x.ID != rect.ID).ToList();

                var topRight = rect.TopRight(others);
                if (topRight == null)
                {
                    continue;
                }

                var top  = topRight.Item2;
                var left = topRight.Item1;

                var colidingRight = others.Where(x => x.Left > left && x.Top >= top && x.Bottom < top);
                var leftMost      = colidingRight.OrderBy(x => x.Left).First();
                var right         = leftMost.Left;

                var colidingBottom = others.Where(x => x.Top < top && ((x.Left <right && x.Left> left) || (x.Right <right && x.Right> left) || (right <x.Right && right> x.Left) || (left <x.Right && left> x.Left)));
                var highest        = colidingBottom.OrderByDescending(x => x.Top).First();
                var bottom         = highest.Top;
                Rectangles.Add(new Rectangle(left, bottom, right, top));
            }
        }
コード例 #6
0
ファイル: CollectionViewTest.cs プロジェクト: ynkbt/moon
        public void HiddenINPCEvents_Add()
        {
            SetSource(Rectangles);
            // These INPC events don't have publicly visible properties so I don't know why/how they're being raised.
            INotifyPropertyChanged source = (INotifyPropertyChanged)View;

            VerifyPropertyChanged("#2", source, () => Rectangles.Add(new Rectangle()), "Count");
        }
コード例 #7
0
ファイル: MainWindowVM.cs プロジェクト: royben/Resonance
 private void _client_RectangleAdded(object sender, RemoteRectAddedEventArgs e)
 {
     if (!Rectangles.Contains(e.Rect)) //Check if we have not received the same rect that we have just finished...
     {
         InvokeUI(() =>
         {
             Rectangles.Add(e.Rect);
         });
     }
 }
コード例 #8
0
        private void LoadCardsToBorder()
        {
            Rectangles.Clear();
            Pictures.Clear();
            int widht  = 8;
            int height = 8;

            PexesoService.StartPexeso(height, widht);
            int x   = 2;
            int y   = 2;
            int row = 0;

            foreach (var a in PexesoService.GameCards)
            {
                Canvas.SetLeft(a.Img, x);
                Canvas.SetTop(a.Img, y);
                // Rectangle
                SolidColorBrush pomCo = new SolidColorBrush()
                {
                    Color   = Colors.Black,
                    Opacity = 1
                };
                SolidColorBrush pomCoB = new SolidColorBrush()
                {
                    Color = Colors.BlueViolet
                };
                Rectangle pomR = new Rectangle()
                {
                    Width  = PexesoService.PictureWidth,
                    Height = PexesoService.PictureHeight,
                    Fill   = pomCo,
                    Stroke = pomCoB,
                };
                Canvas.SetLeft(pomR, x);
                Canvas.SetTop(pomR, y);
                Rectangles.Add(pomR);
                Pictures.Add(a.Img);

                a.PositionX = x;
                a.PositionY = y;
                a.Status    = StatusCardEnum.Covered;
                x          += PexesoService.PictureWidth + 5;
                if (Pictures.Count % widht == 0)
                {
                    row++;
                    x  = 2;
                    y += PexesoService.PictureHeight + 5;
                }
                if (row == height)
                {
                    break;
                }
            }
        }
コード例 #9
0
        public Rectangle PutNextRectangle(Size rectangleSize)
        {
            if (rectangleSize.IsEmpty)
            {
                throw new ArgumentException("Empty rectangle size");
            }
            var rectangle = GetNextRectangle(rectangleSize);

            Rectangles.Add(rectangle);
            return(rectangle);
        }
コード例 #10
0
        public Rectangle PutNextRectangle(Size rectangleSize)
        {
            var newRectangle = algorithm.FindSpaceForRectangle(Center, Rectangles, rectangleSize);

            if (newRectangle != Rectangle.Empty)
            {
                Rectangles.Add(newRectangle);
            }

            return(newRectangle);
        }
コード例 #11
0
        private void DoAddRectangle()
        {
            int PosTop;
            int PosLeft;

            PosTop  = Convert.ToInt32(Rectangles[Rectangles.Count - 1].CanvasTop) + 100;
            PosLeft = Convert.ToInt32(Rectangles[Rectangles.Count - 1].CanvasLeft) + 50;

            Rectangles.Add(new Rectangle {
                CanvasLeft = PosLeft.ToString(), CanvasTop = PosTop.ToString(), Fill = "Red", Height = "100", Width = "100"
            });
        }
コード例 #12
0
ファイル: Sprite.cs プロジェクト: alyons/ChaosDrive
 private void StringToRectangle(List <string> strings)
 {
     foreach (string s in strings)
     {
         string[] tempsS = s.Split(' ');
         int[]    tempI  = new int[tempsS.Length];
         for (int i = 0; i < tempsS.Length; i++)
         {
             tempI[i] = Convert.ToInt32(tempsS[i]);
         }
         Rectangles.Add(new Rectangle(tempI[0], tempI[1], tempI[2], tempI[3]));
     }
 }
コード例 #13
0
        public void FinishRectangle(RemoteRect rect)
        {
            CurrentRect = new RemoteRect();

            InvokeUI(() =>
            {
                Rectangles.Add(rect);
            });

            RectangleAdded?.Invoke(this, new RemoteRectAddedEventArgs()
            {
                Rect = rect
            });
        }
コード例 #14
0
ファイル: DrawingBoard.cs プロジェクト: royben/Resonance
        protected override void OnPreviewMouseUp(MouseButtonEventArgs e)
        {
            base.OnPreviewMouseUp(e);

            if (_isMouseDown)
            {
                _isMouseDown = false;
                Rectangles.Add(CurrentRect);

                FinishRectangleCommand?.Execute(CurrentRect);

                CurrentRect = new RemoteRect();
            }
        }
コード例 #15
0
ファイル: MainWindowVM.cs プロジェクト: royben/Resonance
        protected async override void OnApplicationReady()
        {
            base.OnApplicationReady();

            _transporter = ResonanceTransporter.Builder
                           .Create()
                           .WithUdpAdapter()
                           .WithServer(TcpAdapter.GetLocalIPAddress(), 9999)
                           .WithJsonTranscoding()
                           .Build();

            _transporter.ConnectionLost += (x, e) =>
            {
                e.FailTransporter = true;
                Logger.LogError($"Remote server has closed. {e.Exception.Message}");
            };

            _client = _transporter.CreateClientProxy <IRemoteDrawingBoardService>();
            _client.RectangleAdded += _client_RectangleAdded;

            try
            {
                await _transporter.ConnectAsync();
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, "Could not connect to the remote server. Please restart the application.");
                return;
            }

            //This is just for testing async methods...
            String welcomeMessage = await _client.GetWelcomeMessage("Roy", 99);

            int countAsync = await _client.GetRectanglesCountAsync();

            int sum = await _client.CalcAsync(10, 15);

            try
            {
                foreach (var rect in _client.Rectangles)
                {
                    Rectangles.Add(rect);
                }
            }
            catch (Exception ex)
            {
                //TODO: Add log here that we could not fetch any server logs or something.
            }
        }
コード例 #16
0
        public Rectangle CreateARectangle(Color kledingkleur)
        {
            Rectangle rec = new Rectangle();

            rec.Height = 10;
            rec.Width  = 10;

            SolidColorBrush color = new SolidColorBrush();

            color.Color = kledingkleur;
            rec.Fill    = color;
            Rectangles.Add(rec);

            return(rec);
        }
コード例 #17
0
        public Rectangle PutNextRectangle(Size rectangleSize)
        {
            Rectangle nextRectangle;

            do
            {
                nextRectangle = new Rectangle(Spiral.GetNextPoint(), rectangleSize);
            }while (Rectangles.Any(r => r.IntersectsWith(nextRectangle)));

            if (NeedingShiftToCenter)
            {
                nextRectangle = GetShiftedToCenterRectangle(nextRectangle);
            }
            Rectangles.Add(nextRectangle);
            return(nextRectangle);
        }
コード例 #18
0
 private void Rectangles_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     if (e.OldItems != null)
     {
         foreach (Rectangle rectangle in e.OldItems)
         {
             Rectangles.Remove(rectangle);
         }
     }
     if (e.NewItems != null)
     {
         foreach (Rectangle rectangle in e.NewItems)
         {
             Rectangles.Add(rectangle);
         }
     }
 }
コード例 #19
0
        public Rectangle PutNextRectangle(Size rectangleSize)
        {
            Rectangle nextRectangle;

            do
            {
                var center    = Spiral.GetNextPoint();
                var leftAngle = new Point(center.X - rectangleSize.Width / 2, center.Y - rectangleSize.Height / 2);
                nextRectangle = new Rectangle(leftAngle, rectangleSize);
            } while (Rectangles.Any(r => r.IntersectsWith(nextRectangle)));

            if (NeedingShiftToCenter)
            {
                nextRectangle = GetShiftedToCenterRectangle(nextRectangle);
            }
            Rectangles.Add(nextRectangle);
            return(nextRectangle);
        }
コード例 #20
0
ファイル: MainWindowModel.cs プロジェクト: ozhernakova/Blog
        /// <summary>
        /// Add or update screen rectangle for the view.
        /// </summary>
        private void AddOrUpdateViewRectangle()
        {
            if (Rectangles == null)
            {
                return;
            }
            var screenRectangle = Rectangles.FirstOrDefault(item => ScreenNames.View.Equals(item.Name));

            if (screenRectangle == null)
            {
                screenRectangle = new ScreenRectangle(ScreenNames.View, ViewWidth, ViewHeight);
                Rectangles.Add(screenRectangle);
            }
            else
            {
                screenRectangle.SetSize(ViewWidth, ViewHeight);
            }
        }
コード例 #21
0
        /// <summary>
        /// Generates the data behind all of the
        /// black Tv lines that fill the screen.
        /// </summary>
        /// <param name="graphicsDevice">The game's graphics device</param>
        private void GenerateTvLines(GraphicsDevice graphicsDevice)
        {
            int step = 0;

            for (int i = 0; i < 600; i++)
            {
                if (step == Steps)
                {
                    step = 0;
                    var tex = new Texture2D(graphicsDevice, Length, Height);
                    tex.SetData(Data);
                    Textures.Add(tex);
                    Rectangles.Add(new Rectangle(0, i, Length, Height));
                    i += 2;
                }
                step++;
            }
        }
コード例 #22
0
        /// <summary>
        /// Updates the specified rectangle of the specified box.
        /// </summary>
        /// <param name="box"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="r"></param>
        /// <param name="b"></param>
        internal void UpdateRectangle(CssBox box, double x, double y, double r, double b)
        {
            double leftspacing   = box.ActualBorderLeftWidth + box.ActualPaddingLeft;
            double rightspacing  = box.ActualBorderRightWidth + box.ActualPaddingRight;
            double topspacing    = box.ActualBorderTopWidth + box.ActualPaddingTop;
            double bottomspacing = box.ActualBorderBottomWidth + box.ActualPaddingTop;

            if ((box.FirstHostingLineBox != null && box.FirstHostingLineBox.Equals(this)) || box.IsImage)
            {
                x -= leftspacing;
            }
            if ((box.LastHostingLineBox != null && box.LastHostingLineBox.Equals(this)) || box.IsImage)
            {
                r += rightspacing;
            }

            if (!box.IsImage)
            {
                y -= topspacing;
                b += bottomspacing;
            }


            if (!Rectangles.ContainsKey(box))
            {
                Rectangles.Add(box, RRect.FromLTRB(x, y, r, b));
            }
            else
            {
                RRect f = Rectangles[box];
                Rectangles[box] = RRect.FromLTRB(
                    Math.Min(f.X, x), Math.Min(f.Y, y),
                    Math.Max(f.Right, r), Math.Max(f.Bottom, b));
            }

            //DA NOTE: Need to check prents parent to re-draw inline borders
            if (box.ParentBox != null && box.ParentBox.IsInline)// || box.ParentBox.ParentBox != null && box.ParentBox.ParentBox.IsInline)
            {
                UpdateRectangle(box.ParentBox, x, y, r, b);
            }
        }
コード例 #23
0
ファイル: CssLineBox.cs プロジェクト: Alister742/ParseKit
        /// <summary>
        /// Updates the specified rectangle of the specified box.
        /// </summary>
        /// <param name="box"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="r"></param>
        /// <param name="b"></param>
        internal void UpdateRectangle(CssBox box, float x, float y, float r, float b)
        {
            float leftspacing   = box.ActualBorderLeftWidth + box.ActualPaddingLeft;
            float rightspacing  = box.ActualBorderRightWidth + box.ActualPaddingRight;
            float topspacing    = box.ActualBorderTopWidth + box.ActualPaddingTop;
            float bottomspacing = box.ActualBorderBottomWidth + box.ActualPaddingTop;

            if ((box.FirstHostingLineBox != null && box.FirstHostingLineBox.Equals(this)) || box.IsImage)
            {
                x -= leftspacing;
            }
            if ((box.LastHostingLineBox != null && box.LastHostingLineBox.Equals(this)) || box.IsImage)
            {
                r += rightspacing;
            }

            if (!box.IsImage)
            {
                y -= topspacing;
                b += bottomspacing;
            }


            if (!Rectangles.ContainsKey(box))
            {
                Rectangles.Add(box, RectangleF.FromLTRB(x, y, r, b));
            }
            else
            {
                RectangleF f = Rectangles[box];
                Rectangles[box] = RectangleF.FromLTRB(
                    Math.Min(f.X, x), Math.Min(f.Y, y),
                    Math.Max(f.Right, r), Math.Max(f.Bottom, b));
            }

            if (box.ParentBox != null && box.ParentBox.Display == CssConstants.Inline)
            {
                UpdateRectangle(box.ParentBox, x, y, r, b);
            }
        }
コード例 #24
0
ファイル: GameManager.cs プロジェクト: f-vojnovski/RectSlayer
        // Randomly generates rectangles and powerUps on every level.
        // First it chooses a position for the plus powerUp, then
        // for the remaining positions randomly chooses if it will be a rectangle or powerUp or empty space.
        // High probability for a rectangle, low probability for a powerUp or empty space.
        public void GenerateObjects()
        {
            int        height        = top + objectHeight + 3;
            int        step          = 80;
            int        extraStep     = step / 5;
            int        startingPoint = left + 6;
            List <int> positions     = new List <int>();

            for (int i = 0; i < objectsToGenerate; i++)
            {
                positions.Add(i);
            }

            // plus powerUp - generate position
            int rnd = random.Next(objectsToGenerate);

            positions.Remove(rnd);
            Point plusPosition = new Point(startingPoint + rnd * step + extraStep, height);

            PowerUps.Add(powerUpFactory.GeneratePowerUp(plusPosition, "plus")); //plus powerUp

            foreach (int pos in positions)
            {
                rnd = random.Next(11);

                if (rnd < 7)
                {
                    Point point = new Point(startingPoint + pos * step, height);
                    Rectangles.Add(new Rectangle(point, rectWidth, objectHeight, Color.Blue, Level));
                }
                else if (rnd < 9)
                {
                    Point point = new Point(startingPoint + pos * step + extraStep, height);
                    PowerUps.Add(powerUpFactory.GeneratePowerUp(point, random.Next(10)));
                }
                //else -> empty position
            }
        }
コード例 #25
0
        public new Rectangle PutNextRectangle(Size rectangleSize)
        {
            foreach (var point in Spiral.GetPoints(center))
            {
                var rectangle =
                    new Rectangle(new Point(point.X - rectangleSize.Width / 2, point.Y - rectangleSize.Height / 2),
                                  rectangleSize);
                if (Rectangles.Any(r => r.Contains(point)))
                {
                    continue;
                }
                if (HasOverlappingRectangles(rectangle, Rectangles))
                {
                    continue;
                }

                Rectangles.Add(rectangle);
                return(rectangle);
            }

            // до суда потенциально не дойдет, т.к. спираль выдает бесконечно точки
            return(new Rectangle());
        }
コード例 #26
0
        private Rectangles AjoutRec(Rectangles recs, ref Rectangle rec)
        {
            Rectangles rectangles = new Rectangles();

            if (recs.Count == 0)
            {
                return(recs);
            }
            foreach (var rectangle in recs)
            {
                Rectangle r = rectangle.Fuze(rec);
                if (r == null)
                {
                    rectangles.Add(rectangle);
                }
                else
                {
                    rectangles = AjoutRec(rectangles, ref r);
                    rec        = r;
                }
            }
            return(rectangles);
        }
コード例 #27
0
 /// <summary>
 /// Adds rectangle object at scene
 /// </summary>
 /// <param name="rectangle">Rectangle object</param>
 public void AddRectangle(RectangleObject rectangle)
 {
     Rectangles.Add(rectangle);
 }
コード例 #28
0
 public void AddRectangle(Point teme, int width, int height, Color color)
 {
     Rectangles.Add(new Rectangle(teme, width, height, color));
 }
コード例 #29
0
        public Chessboard()
        {
            _centerPointF = new PointF(RenderForm.Width / 2f, RenderForm.Height / 2f);

            // Create colors
            var cRed     = new Mathe.RawColor4(237 / 255f, 28 / 255f, 36 / 255f, 1);
            var cGreen   = new Mathe.RawColor4(34 / 255f, 177 / 255f, 76 / 255f, 1);
            var cYellow  = new Mathe.RawColor4(255 / 255f, 243 / 255f, 0 / 255f, 1);
            var cPirple  = new Mathe.RawColor4(163 / 255f, 72 / 255f, 165 / 255f, 1);
            var cBlue    = new Mathe.RawColor4(0 / 255f, 163 / 255f, 233 / 255f, 1);
            var cGrey    = new Mathe.RawColor4(195 / 255f, 195 / 255f, 195 / 255f, 1);
            var cWhite   = new Mathe.RawColor4(1, 1, 1, 1);
            var cYellow2 = new Mathe.RawColor4(226 / 255f, 234 / 255f, 152 / 255f, 0.8f);

            // Create brushes
            _yellowBrush = new D2D.SolidColorBrush(RenderForm.RenderTarget, cYellow2);
            _blueBrush   = new D2D.SolidColorBrush(RenderForm.RenderTarget, cBlue);
            _redBrush    = new D2D.SolidColorBrush(RenderForm.RenderTarget, cRed);
            _maskBrush   = new D2D.SolidColorBrush(RenderForm.RenderTarget, new Mathe.RawColor4(0, 0, 0, 0.5f));

            LoadSettings();
            int intI = 0;

            // Create rectangles
            for (var index = 0; index < Boards.Count; index++)
            {
                var item = Boards[index];
                _rectangles.Add(new Mathe.RawRectangleF[item.X, item.Y]);
                _brushes.Add(new D2D.Brush[item.X, item.Y]);
                const float recWidth = 51, margin = 5;

                float widthC  = recWidth * item.X + margin * (item.X - 1),
                      heightC = recWidth * item.Y + margin * (item.Y - 1),
                      leftC   = _centerPointF.X - widthC / 2,
                      topC    = _centerPointF.Y - heightC / 2;

                for (var i = 0; i < item.X; i++)
                {
                    for (var j = 0; j < item.Y; j++)
                    {
                        if (item.VisibleBoard[i, j] == 0)
                        {
                            continue;
                        }
                        float left = leftC + i * (recWidth + margin), top = topC + j * (recWidth + margin);
                        _rectangles[index][i, j] = new Mathe.RawRectangleF(left, top, left + recWidth, top + recWidth);
                        _brushes[index][i, j]    = new D2D.SolidColorBrush(RenderForm.RenderTarget, item.Color[i, j]);
                        Rectangles.Add(_rectangles[index][i, j]);
                        _boardMap.Add(_rectangles[index][i, j], intI);
                        intI++;
                    }
                }
            }

            #region ImageNormal settings
            //_boardCentre.SetNormalImage(0, 2, LoadFromFile(Path.Combine(_resPath, "13.png")));

            //_boardCentre.SetNormalImage(1, 1, LoadFromFile(Path.Combine(_resPath, "1A.png")));
            //_boardCentre.SetNormalImage(1, 2, LoadFromFile(Path.Combine(_resPath, "6.png")));
            //_boardCentre.SetNormalImage(1, 3, LoadFromFile(Path.Combine(_resPath, "9.png")));

            //_boardCentre.SetNormalImage(2, 0, LoadFromFile(Path.Combine(_resPath, "12.png")));
            //_boardCentre.SetNormalImage(2, 1, LoadFromFile(Path.Combine(_resPath, "2.png")));
            //_boardCentre.SetNormalImage(2, 2, LoadFromFile(Path.Combine(_resPath, "7C.png")));
            //_boardCentre.SetNormalImage(2, 3, LoadFromFile(Path.Combine(_resPath, "8.png")));
            //_boardCentre.SetNormalImage(2, 4, LoadFromFile(Path.Combine(_resPath, "10.png")));

            //_boardCentre.SetNormalImage(3, 1, LoadFromFile(Path.Combine(_resPath, "3.png")));
            //_boardCentre.SetNormalImage(3, 2, LoadFromFile(Path.Combine(_resPath, "4.png")));
            //_boardCentre.SetNormalImage(3, 3, LoadFromFile(Path.Combine(_resPath, "5.png")));

            //_boardCentre.SetNormalImage(4, 2, LoadFromFile(Path.Combine(_resPath, "11.png")));
            #endregion
        }
コード例 #30
0
        private void SetImg(string path)
        {
            try
            {
                Bitmap oldBitmap = new Bitmap(path);
                oldBitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);

                Image <Gray, Byte> matimg = OtsuThreshold(oldBitmap);
                matimg = matimg.SmoothMedian(11);
                Image <Gray, Byte> edges = new Image <Gray, byte>(oldBitmap.Width, oldBitmap.Height);

                Image <Bgr, Byte> contoursimg = new Image <Bgr, byte>(oldBitmap);

                Mat hierarchy = new Mat();

                VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
                //VectorOfVectorOfPointF VectorOfPointF = new VectorOfVectorOfPointF();

                CvInvoke.Canny(matimg, edges, 0, 200);

                CvInvoke.FindContours(edges,
                                      contours,
                                      hierarchy,
                                      RetrType.Tree,
                                      ChainApproxMethod.ChainApproxSimple);
                List <int> fater_contours = new List <int>();

                int[,,] arraylist = ((int[, , ])(hierarchy.GetData()));

                for (int k = 0; k < contours.Size; k++)
                {
                    int i = k;
                    int c = 0;
                    while (arraylist[0, i, 2] != -1)
                    {
                        i = arraylist[0, i, 2];
                        c = c + 1;
                        if (c > 4)
                        {
                            fater_contours.Add(k);
                        }
                    }
                }
                for (int j = 0; j < fater_contours.Count; j++)
                {
                    RotatedRect rect = CvInvoke.MinAreaRect(contours[fater_contours[j]]); //minAreaRect
                    MudelSize = rect.Size.Width > rect.Size.Height ?  (int)rect.Size.Height :  (int)rect.Size.Width;

                    PointF[] pf = CvInvoke.BoxPoints(rect);//BoxPoints();

                    Point[] point = new Point[pf.Length];

                    int[] pointx = new int[4];
                    int[] pointy = new int[4];
                    for (int i = 0; i < pf.Length; i++)
                    {
                        pointx[i] = (int)pf[i].X;
                        pointy[i] = (int)pf[i].Y;
                    }
                    Rectangles.Add(new Rectangle()
                    {
                        X = pointx.Min(), Y = pointy.Min(), Width = MudelSize, Height = MudelSize
                    });

                    contoursimg.Draw(rect, new Bgr(255, 0, 0), 2);
                    // CvInvoke.DrawContours(new Image<Bgr, Byte>(newBitmap), VectorOfPointF, -1, new MCvScalar(0, 255, 0), 1, LineType.AntiAlias);
                }
            }
            catch (Exception ex)
            {
                //  return null;
                //  MessageBox.Show(ex.Message, "信息提示");
            }
        }