2013-02-09 144 views
1

輪廓一些色彩檢測和二進制閾值後,我用下面的代碼,以查找輪廓,並吸引他們到圖像:約計與旋轉矩形

using (MemStorage stor = new MemStorage()) 
     { 
      Contour<Point> contours = img.FindContours(
       Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_SIMPLE, 
       Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_LIST, 
       stor); 

      for (; contours != null; contours = contours.HNext) 
      { 
       Contour<Point> currentContour = contours.ApproxPoly(contours.Perimeter * poly, stor); 

       img.Draw(currentContour,new Bgr(255,255,255),1); 

       Rectangle currentrect = currentContour.BoundingRectangle; 

       img.Draw(currentrect,new Bgr(255,255,255),2); 
      } 
     } 

我的問題是,如我所料,如果輪廓是矩形但在圖像中旋轉,邊界矩形不會改變其方向以適應旋轉。他們的另一種方式是完成這個功能嗎?任何幫助將不勝感激。

回答

2

是的,還有另一種方法來實現這一點。你可以使用

contour.GetConvexHull(ORIENTATION.CV_CLOCKWISE); 

使用矩,你可以很容易地獲得方向並相應地調整矩形。