예제 #1
0
 private static Rectangle[] FindRectangles(Image<Gray, byte> gray)
 {
     var result = new List<Rectangle>();
     for (var contour = gray.FindContours(); contour != null; contour = contour.HNext) {
         var rect = contour.BoundingRectangle;
         result.Add(new Rectangle(rect.X, rect.Y, rect.Width - 1, rect.Height - 1));
     //                result.Add(rect);
     }
     return result.ToArray();
 }
예제 #2
0
        /// <summary>
        /// Extract paper contours from an HSV image.
        /// </summary>
        /// <param name="binaryImage">HSV image to extract paper contours from.</param>
        /// <returns>Paper contours extracted.</returns>
        public List<Contour<Point>> extractPaperContours(Image<Gray, byte> binaryImage)
        {
            List<Contour<Point>> paperContours = new List<Contour<Point>>();

            using(MemStorage storage = new MemStorage())
            {
                for (Contour<Point> contour = binaryImage.FindContours(); contour != null; contour = contour.HNext)
                {

                    if((contour.BoundingRectangle.Height * contour.BoundingRectangle.Width) >= (binaryImage.Height * binaryImage.Width * CONTOUR_AREA_PERCENTAGE_THRESHOLD))
                    {
                        paperContours.Add(contour);
                    }
                }
            }

            return paperContours;
        }