OpenCV 3.0 findContours crashes
<p>I need to detect the object's contour of an image. For that purpose, I'm using the OpenCV library's function <code>findContours</code>. I'm using <code>OpenCV 3.0 (x86)</code> on <code>Windows 10 (x64)</code> compiled by me with the <code>contrib modules</code>.</p>

<h1>The problem</h1>

<p>The problem is that, when I try to use this function, the application crashes. The error is not an exception or an assertion failure, I can only see a window saying to me that the application has crashed:</p>

<p><a href="https://i.stack.imgur.com/6IPiR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6IPiR.png" alt="enter image description here"></a></p>

<h1>What I have tested</h1>

<p>I have checked that the image I'm passing to <code>findContours</code> is a binary image:</p>

<p>I have checked the type of the image, which is 0, the same as <code>CV_8U</code> value.</p>

<p>I have even checked the histogram, and there are only pixels with values 0 and 1.</p>

<p>I have also searched for examples from OpenCV tutorials and forums, and I have tried to do exactly the same than in the example, and the program crashes again.</p>

<h1>The code</h1>

<p>Here is the code that I'm executing:</p>

<pre><code>// This is the main function:
int test_findContours(const std::string &amp;path){
    Mat img = imread(path, IMREAD_GRAYSCALE);
    if (!img.data){
        cout &lt;&lt; "ERROR" &lt;&lt; endl;
        return -1;
    }
    Mat mask;
    getRemBackgroundMask(img, mask);

    vector&lt; vector&lt;Point&gt; &gt; contours;

    // Here the program crashes:
    findContours(mask, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
    return 0;
}

// Get the mask to remove the background
void getRemBackgroundMask(const Mat &amp;img, Mat &amp;mask) {
    threshold(img, mask, 70, 1, THRESH_BINARY_INV);

    Mat kernel = getStructuringElement(MORPH_RECT, Size(3, 3));
    openning(mask, mask, kernel);
}

void openning(const Mat &amp;binary, Mat &amp;result, const Mat &amp;kernel){
    erode(binary, result, kernel);
    dilate(binary, result, kernel);
}
</code></pre>