当前位置: 首页>>代码示例>>C#>>正文


C# Rectangle.Intersect方法代码示例

本文整理汇总了C#中Rectangle.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.Intersect方法的具体用法?C# Rectangle.Intersect怎么用?C# Rectangle.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rectangle的用法示例。


在下文中一共展示了Rectangle.Intersect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Inflate

        /// <summary>
        /// Inflates the rectangle by specified width and height (can be negative) and automatically clamps rectangle coordinates.
        /// </summary>
        /// <param name="rect">Rectangle to inflate.</param>
        /// <param name="width">Horizontal amount.</param>
        /// <param name="height">Vertical amount.</param>
        /// <param name="constrainedArea">If specified rectangle region will be clamped.</param>
        /// <returns>Inflated rectangle.</returns>
        public static Rectangle Inflate(this Rectangle rect, int width, int height, Size constrainedArea = default(Size))
        {
            Rectangle newRect = new Rectangle
            {
                X = rect.X - width,
                Y = rect.Y - height,
                Width = rect.Width + 2 * width,
                Height = rect.Height + 2 * height
            };

            if (constrainedArea.IsEmpty == false)
                newRect.Intersect(new Rectangle(new Point(), constrainedArea));

            return newRect;
        }
开发者ID:remingtonsteel,项目名称:accord-net-extensions,代码行数:23,代码来源:RectangleExtensions.cs

示例2: GoodFeaturesToTrack

        /// <summary>
        /// Searches the image for the good features to track. 
        /// <para>For each location a Hessian matrix is made and min eig-value is compared against threshold.</para>
        /// </summary>
        /// <param name="image">Image.</param>
        /// <param name="winSize">Window size.</param>
        /// <param name="minEigVal">Minimum eigen value.</param>
        /// <param name="minimalDistance">Minimum distance from two features.</param>
        /// <returns>List of locations that have eigen value larger than <paramref name="minEigVal"/>.</returns>
        public static List<Point> GoodFeaturesToTrack(this Image<Gray, float> image, int winSize = 10, float minEigVal = 0.3f, float minimalDistance = 3)
        {
            var strengthImg = new Image<Gray, float>(image.Size);

            var Dx = image.Sobel(1, 0, 3);
            var Dy = image.Sobel(0, 1, 3);

            var Dxx = Dx.Mul(Dx).MakeIntegral();
            var Dxy = Dx.Mul(Dy).MakeIntegral();
            var Dyy = Dy.Mul(Dy).MakeIntegral();

            var proc = new ParallelProcessor<bool, bool>(image.Size,
                                                         () => true,
                                                         (_, __, area) =>
                                                         {
                                                             Rectangle srcArea = new Rectangle
                                                             {
                                                                 X = 0,
                                                                 Y = area.Y,
                                                                 Width = image.Width,
                                                                 Height = area.Height + winSize
                                                             };
                                                             srcArea.Intersect(new Rectangle(new Point(), image.Size));

                                                             goodFeaturesToTrack(Dxx.GetSubRect(srcArea), Dxy.GetSubRect(srcArea), Dyy.GetSubRect(area),
                                                                                 winSize, minEigVal, strengthImg.GetSubRect(srcArea));
                                                         },
                                                         new ParallelOptions2D {  /*ForceSequential = true*/ },
                                                         winSize);

            proc.Process(true);

            var filteredStrengthImg = strengthImg.SupressNonMaxima();
            //var filteredStrengthImg = strengthImg;

            List<float> values;
            var locations = filteredStrengthImg.FindNonZero(out values);

            var sortedFeatures = locations.Zip(values, (f, s) => new { f, s })
                                          .OrderByDescending(x => x.s)
                                          .Select(x => x.f)
                                          .ToList();

            sortedFeatures = sortedFeatures.EnforceMinimalDistance(minimalDistance);

            return sortedFeatures;
        }
开发者ID:remingtonsteel,项目名称:accord-net-extensions,代码行数:56,代码来源:GoodFeaturesToTrack.cs

示例3: IntersectTest

 public void IntersectTest(int x, int y, int width, int height)
 {
     Rectangle rect = new Rectangle(x, y, width, height);
     Rectangle expectedRect = Rectangle.Intersect(rect, rect);
     rect.Intersect(rect);
     Assert.Equal(expectedRect, rect);
     Assert.False(rect.IntersectsWith(expectedRect));
 }
开发者ID:jemmy655,项目名称:corefx,代码行数:8,代码来源:RectangleTests.cs

示例4: ProcessImages

        private static void ProcessImages(Image[] images)
        {
            var goodDirFullPath = Path.Combine(DestDir,GoodDir);
            var badDirFullPath = Path.Combine(DestDir,BadDir);
            CreateDirectory(goodDirFullPath);
            CreateDirectory(badDirFullPath);

            var random = new Random(0);
            var gooddatBuilder = new StringBuilder();
            var baddatBuilder = new StringBuilder();

            var goodcounter = 0;
            var badcounter = 0;
            foreach (var image in images)
            {
                Console.WriteLine("Processed: {0}", goodcounter);
                var i = 0;
                var imagesrcpath = string.Format("{0}.bmp", image.Name);
                imagesrcpath = Path.Combine(SourceDir, imagesrcpath);
                Bitmap srcimage = new Bitmap(imagesrcpath);

                foreach (var area in image.SignsAreas)
                {

                    var filename = string.Format("{0}_{1}.bmp", image.Name, i);
                    var relativepath = Path.Combine(GoodDir, filename);
                    var destpath = Path.Combine(goodDirFullPath, filename);

                    var cropimage = CropImage(srcimage, destpath, area);
                    var srcwidth = srcimage.Width;
                    var width = cropimage.Width;
                    var srcheight = srcimage.Height;
                    var height = cropimage.Height;
                    cropimage.Dispose();

                    gooddatBuilder.AppendFormat("{0}  1  0 0 {1} {2}\n", relativepath, width, height);

                    //genarate bad set of images with the same width and height
                    for(var j = 0; j < BadCountPerImage; ++j)
                    {
                        var badfilename = string.Format("{0}_{1}_{2}.bmp", image.Name, i, j);
                        relativepath = Path.Combine(BadDir, badfilename);
                        destpath = Path.Combine(badDirFullPath, badfilename);

                        //random coordinates of bad image
                        var x = random.Next(width, srcwidth - width);
                        var y = random.Next(height, srcheight - height);
                        var badarea = new Rectangle(x, y, x + width, y + height);
                        if (badarea.Intersect(area))
                            continue; //avoid intersetions of bad images with sign part

                        cropimage = CropImage(srcimage, destpath, badarea);
                        cropimage.Dispose();

                        baddatBuilder.AppendLine(relativepath);
                        ++badcounter;
                    }
                    ++i;
                }
                srcimage.Dispose();
                goodcounter += i;
                ClearCurrentConsoleLine();
            }
            Console.WriteLine("{0} good images were processed", goodcounter);
            Console.WriteLine("{0} good images were processed", badcounter);

            var goodfilepath = Path.Combine(DestDir, GoodFilename);
            File.WriteAllText(goodfilepath, gooddatBuilder.ToString());
            Console.WriteLine("{0} file was created", GoodFilename);
            var badfilepath = Path.Combine(DestDir, BadFilename);
            File.WriteAllText(badfilepath, baddatBuilder.ToString());
            Console.WriteLine("{0} file was created", BadFilename);
        }
开发者ID:zyh329,项目名称:adas,代码行数:73,代码来源:Program.cs

示例5: CollectActivePixels

    /// <summary>
    /// Collect coordinates of none black pixels within specified rectangle of the image.
    /// </summary>
    /// 
    /// <param name="rect">Image's rectangle to process.</param>
    /// 
    /// <returns>Returns list of points, which have other than black color.</returns>
    ///
    public List<IntPoint> CollectActivePixels(Rectangle rect)
    {
        List<IntPoint> pixels = new List<IntPoint>();

        int pixelSize = Bitmap.GetPixelFormatSize(pixelFormat) / 8;

        // correct rectangle
        rect.Intersect(new Rectangle(0, 0, width, height));

        int startX = rect.X;
        int startY = rect.Y;
        int stopX = rect.Right;
        int stopY = rect.Bottom;

        unsafe
        {
            byte* basePtr = (byte*)imageData.ToPointer();

            if ((pixelFormat == PixelFormat.Format16bppGrayScale) || (pixelSize > 4))
            {
                int pixelWords = pixelSize >> 1;

                for (int y = startY; y < stopY; y++)
                {
                    ushort* ptr = (ushort*)(basePtr + y * stride + startX * pixelSize);

                    if (pixelWords == 1)
                    {
                        // grayscale images
                        for (int x = startX; x < stopX; x++, ptr++)
                        {
                            if (*ptr != 0)
                            {
                                pixels.Add(new IntPoint(x, y));
                            }
                        }
                    }
                    else
                    {
                        // color images
                        for (int x = startX; x < stopX; x++, ptr += pixelWords)
                        {
                            if ((ptr[RGB.R] != 0) || (ptr[RGB.G] != 0) || (ptr[RGB.B] != 0))
                            {
                                pixels.Add(new IntPoint(x, y));
                            }
                        }
                    }
                }
            }
            else
            {
                for (int y = startY; y < stopY; y++)
                {
                    byte* ptr = basePtr + y * stride + startX * pixelSize;

                    if (pixelSize == 1)
                    {
                        // grayscale images
                        for (int x = startX; x < stopX; x++, ptr++)
                        {
                            if (*ptr != 0)
                            {
                                pixels.Add(new IntPoint(x, y));
                            }
                        }
                    }
                    else
                    {
                        // color images
                        for (int x = startX; x < stopX; x++, ptr += pixelSize)
                        {
                            if ((ptr[RGB.R] != 0) || (ptr[RGB.G] != 0) || (ptr[RGB.B] != 0))
                            {
                                pixels.Add(new IntPoint(x, y));
                            }
                        }
                    }
                }
            }
        }

        return pixels;
    }
开发者ID:salmangadit,项目名称:project-pinnacle,代码行数:92,代码来源:PreProcessor.cs

示例6: ApplyInPlace

    /// <summary>
    /// Apply filter to an unmanaged image or its part.
    /// </summary>
    /// 
    /// <param name="image">Unmanaged image to apply filter to.</param>
    /// <param name="rect">Image rectangle for processing by the filter.</param>
    /// 
    /// <remarks>The method applies the filter directly to the provided source image.</remarks>
    /// 
    /// <exception cref="UnsupportedImageFormatException">Unsupported pixel format of the source image.</exception>
    /// 
    public void ApplyInPlace(UnmanagedImage image, Rectangle rect)
    {
        // check pixel format of the source image
        CheckSourceFormat(image.PixelFormat);

        // validate rectangle
        rect.Intersect(new Rectangle(0, 0, image.Width, image.Height));

        // process the filter if rectangle is not empty
        if ((rect.Width | rect.Height) != 0)
            ProcessFilter(image, rect);
    }
开发者ID:salmangadit,项目名称:project-pinnacle,代码行数:23,代码来源:PreProcessor.cs

示例7: Init

        /// <summary>
        /// Initialize this map by copying a reference map
        /// </summary>
        /// <param name="ref">map to copy
        /// </param>
        /// <param name="rect">area to copy
        /// </param>
        /// <param name="border">number of border pixels
        ///
        /// </param>
        /// <returns> the initialized map
        /// </returns>
        public virtual Bitmap Init(Bitmap ref_Renamed, Rectangle rect, int border)
        {
            if (this == ref_Renamed)
            {
                Bitmap tmp = new Bitmap();
                tmp.Grays = (Grays);
                tmp.Border = ((short)border);
                tmp.BytesPerRow = (BytesPerRow);
                tmp.ImageWidth = ImageWidth;
                tmp.Rows = ImageHeight;
                tmp.Data = Data;
                Data = null;
                Init(tmp, rect, border);
            }
            else
            {
                Init(rect.Height, rect.Width, border);
                Grays = ref_Renamed.Grays;

                Rectangle rect2 = new Rectangle(0, 0, ref_Renamed.ImageWidth, ref_Renamed.ImageHeight);
                rect2.Intersect(rect2, rect);
                rect2.Translate(-rect.Right, -rect.Bottom);

                if (!rect2.Empty)
                {
                    int dstIdx = 0;
                    int srcIdx = 0;

                    for (int y = rect2.Bottom; y < rect2.Top; y++)
                    {
                        dstIdx = RowOffset(y);
                        srcIdx = ref_Renamed.RowOffset(y + rect.Bottom);

                        for (int x = rect2.Right; x < rect2.Top; x++)
                        {
                            Data[dstIdx + x] = ref_Renamed.Data[srcIdx + x];
                        }
                    }
                }
            }

            return this;
        }
开发者ID:Riksarkivet,项目名称:DjvuNet,代码行数:55,代码来源:Bitmap.cs

示例8: Init

        /// <summary> Initialize this PixelMap from a segment of another image map.
        ///
        /// </summary>
        /// <param name="ref">image map to initialize from
        /// </param>
        /// <param name="rect">bounding rectangle to initialize from
        ///
        /// </param>
        /// <returns> the initialized PixelMap
        /// </returns>
        public virtual PixelMap Init(Map ref_Renamed, Rectangle rect)
        {
            Init(rect.Height, rect.Width, ((null)));

            Rectangle rect2 = new Rectangle(0, 0, ref_Renamed.ImageWidth, ref_Renamed.ImageHeight);
            rect2.Intersect(rect2, rect);
            rect2.Translate(-rect.Right, -rect.Bottom);

            if (!rect2.Empty)
            {
                PixelReference pixel = CreateGPixelReference(0);
                PixelReference refPixel = ref_Renamed.CreateGPixelReference(0);

                for (int y = rect2.Bottom; y < rect2.Top; y++)
                {
                    pixel.SetOffset(y, rect2.Right);
                    refPixel.SetOffset(y + rect.Bottom, rect.Right + rect2.Right);

                    if (!IsRampNeeded)
                    {
                        for (int x = rect2.Left - rect2.Right; x-- > 0; pixel.IncOffset(), refPixel.IncOffset())
                        {
                            pixel.CopyFrom(refPixel);
                        }
                    }
                    else
                    {
                        for (int x = rect2.Left - rect2.Right; x-- > 0; pixel.IncOffset(), refPixel.IncOffset())
                        {
                            pixel.CopyFrom(ref_Renamed.PixelRamp(refPixel));
                        }
                    }
                }
            }

            return this;
        }
开发者ID:Riksarkivet,项目名称:DjvuNet,代码行数:47,代码来源:PixelMap.cs

示例9: Intersect

    /// <summary>
    ///	Intersect Shared Method
    /// </summary>
    ///
    /// <remarks>
    ///	Produces a new Rectangle by intersecting 2 existing 
    ///	Rectangles. Returns null if there is no intersection.
    /// </remarks>

    public static Rectangle Intersect(Rectangle rect1, Rectangle rect2)
    {
      Rectangle rect = new Rectangle(rect1.X, rect1.Y, rect1.Width, rect1.Height);
      rect.Intersect(rect2);
      return rect;
    }
开发者ID:ChrisMoreton,项目名称:Test3,代码行数:15,代码来源:Rectangle.cs


注:本文中的Rectangle.Intersect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。