Frage

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.

War es hilfreich?

Lösung

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!!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top