문제

using (MemStorage storage = new MemStorage()) //allocate storage for contour approximation
         for (Contour<Point> contours = grayImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, storage); contours != null; contours = contours.HNext)
         {
             Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.05, storage);
            canny.Draw(new Rectangle(currentContour.BoundingRectangle.X, currentContour.BoundingRectangle.Y, currentContour.BoundingRectangle.Width, currentContour.BoundingRectangle.Height), new Gray(1), 1);
             canny.Draw(contours, new Gray(), 2);
         }

this code giving me the bounding boxes but not up to mark,in some cases contours is out of box. unable to share sample output image because it require 10 reputation if anybody have solution to this please reply! thankyou.

도움이 되었습니까?

해결책

Image<Gray, Byte> canny = new Image<Gray, byte>(grayImage.Size);
     using (MemStorage storage = new MemStorage())
     for (Contour<Point> contours =grayImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_TREE, storage); contours != null; contours = contours.HNext)
     {
         //Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * 0.05, storage);
         CvInvoke.cvDrawContours(canny, contours, new MCvScalar(255), new MCvScalar(255), -1, 1, Emgu.CV.CvEnum.LINE_TYPE.EIGHT_CONNECTED, new Point(0, 0));
     }
using (MemStorage store = new MemStorage())
         for (Contour<Point> contours1= grayImage.FindContours(Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_NONE, Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_TREE, store); contours1 != null; contours1 = contours1.HNext)
         {
             Rectangle r = CvInvoke.cvBoundingRect(contours1, 1);
             canny.Draw(r, new Gray(255), 1);
         }

this method is giving me perfect bounding box!!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top