OpenCVSharp's findContour returns wrong data
<p>I am trying to implement a function that finds contours in a binary image and filter out small ones.</p>

<p>Here's my code and a sample image. It's a super simple function that removes small area blobs. But I keep getting "contours of edges" instead of contours of regions. :S</p>

<pre><code>    private IplImage RemoveNoise( IplImage image, int minArea )
    {

        List&lt;CvPoint[]&gt; listOfPoints = new List&lt;CvPoint[]&gt;();

        CvSeq&lt;CvPoint&gt; contoursRaw;

        List&lt;ContourData&gt; contours = new List&lt;ContourData&gt;();
        using( CvMemStorage storage = new CvMemStorage() )
        {
            //find contoures
            //Cv.FindContours( image, storage, out contoursRaw );
            Cv.FindContours( image, storage, out contoursRaw, CvContour.SizeOf, ContourRetrieval.Tree, ContourChain.ApproxSimple );
            //contoursRaw = Cv.ApproxPoly( contoursRaw, CvContour.SizeOf, storage, ApproxPolyMethod.DP, 3, true );

            while( contoursRaw != null )
            {
                CvSeq&lt;CvPoint&gt; result = contoursRaw;
                double area = Cv.ContourArea( result );

                //filter out small regions
                if( area &gt;= minArea )
                {                   
                    List&lt;CvPoint&gt; points = new List&lt;CvPoint&gt;();
                    int i = 0;
                    while( result[ i ] != null )
                    {
                        points.Add( new CvPoint( result[ i ].Value.X, result[ i ].Value.Y ) );
                        i++;
                    }
                    listOfPoints.Add( points.ToArray() );

                }
                contoursRaw = contoursRaw.HNext;
            }
        }

        // draw large regions
        IplImage output = new IplImage( image.Size, image.Depth, 1 );
        output.Set( CvColor.Black );
        CvPoint[][] ArrayOfPoints = listOfPoints.ToArray();
        output.FillPoly( ArrayOfPoints, CvColor.White );

        return output;
    }
</code></pre>

<p>Why do I keep getting "contour of edges" instead of contour of regions?</p>

<p>And here is the result:
<a href="https://i.stack.imgur.com/c8yKx.jpg" rel="nofollow noreferrer">enter image description here</a>
<a href="https://i.stack.imgur.com/8x8bm.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8x8bm.jpg" alt="enter image description here"></a></p>