2012-01-07 20 views
0

私はここでのコードのようなstd::vector<std::vector<cv::Point>>::const_iteratorを使用します。C#とEmguCVのイテレータの使い方は? OpenCVので

std::vector<std::vector<cv::Point>> contours; 
cv::findContours(contour,contours,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE);  
std::vector<std::vector<cv::Point>>::const_iterator itContours = contours.begin(); 

while(itContours != contours.end()) 
{ 
    if(Condition1) 
     itContours = contours.erase(itContours); 
    else if(Condition2) 
    itContours = contours.erase(itContours); 
    else if(Condition3) 
     itContours = contours.erase(itContours); 
    else 
     ++itContours; 
} 

しかし、今、私はEmguCVを使用して起動するが、私は上記のコードのように行う方法を見つけることができません。どうしたらいいですか?

答えて

1

EMGU.Examplesフォルダの形状検出の例を見てください。それは輪郭を扱う方法を示します。私はあなたの参照のための以下の関連するコードをコピーしましたが、例を見ている方がはるかに良いです。

 #region Find triangles and rectangles 
     List<Triangle2DF> triangleList = new List<Triangle2DF>(); 
     List<MCvBox2D> boxList = new List<MCvBox2D>(); //a box is a rotated rectangle 

     using (MemStorage storage = new MemStorage()) //allocate storage for contour approximation 
      for (Contour<Point> contours = cannyEdges.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); 

       if (currentContour.Area > 250) //only consider contours with area greater than 250 
       { 
       if (currentContour.Total == 3) //The contour has 3 vertices, it is a triangle 
       { 
        Point[] pts = currentContour.ToArray(); 
        triangleList.Add(new Triangle2DF(
         pts[0], 
         pts[1], 
         pts[2] 
         )); 
       } 
       else if (currentContour.Total == 4) //The contour has 4 vertices. 
       { 
        #region determine if all the angles in the contour are within [80, 100] degree 
        bool isRectangle = true; 
        Point[] pts = currentContour.ToArray(); 
        LineSegment2D[] edges = PointCollection.PolyLine(pts, true); 

        for (int i = 0; i < edges.Length; i++) 
        { 
         double angle = Math.Abs(
          edges[(i + 1) % edges.Length].GetExteriorAngleDegree(edges[i])); 
         if (angle < 80 || angle > 100) 
         { 
          isRectangle = false; 
          break; 
         } 
        } 
        #endregion 

        if (isRectangle) boxList.Add(currentContour.GetMinAreaRect()); 
       } 
       } 
      } 
     #endregion 

乾杯、

クリス

、さらにサポートが必要な場合や、エラーがポップアップした場合、私に教えてください