Repository: opencv
Issue: findContours() is not for 8-connected neighbours but for 4-connected neighbours?
Labels: bug,auto-transferred,category: imgproc,affected: 2.4,affected: 3.4

Transferred from http://code.opencv.org/issues/4448

```
|| thesby thesby on 2015-06-29 09:16
|| Priority: High
|| Affected: branch 'master' (3.0-dev)
|| Category: None
|| Tracker: Bug
|| Difficulty: 
|| PR: 
|| Platform: x86 / Windows
```
## findContours() is not for 8-connected neighbours but for 4-connected neighbours?

```
Thank you for your reading.
I have report the same bug #4444 as opencv2.4.9, but I found the bug exists in opencv3.0 too, so I want to report again.
I draw a binary picture, and set all pixels as 0. Then I set '1' to the diagonal pixels.  If findContours really use 8-connected neighbours, it will find only one connected region.  Actually, it does not. it just find many regions. Thus, I doubt if findContours() use 4-connected neighbours, not 4-connected neighbours as the document depicts.  In addition, I use CV_CHAIN_APPROX_NONE.
That's my code.

int main()
{
    using namespace cv;
    Scalar color{ 255 };
    cv::Mat mbin(700, 700, CV_8UC1);
    mbin.setTo(cv::Scalar::all(255));
    cv::rectangle(mbin, Point(10, 10), Point(200, 200), 0, -1);
    /*cv::rectangle(mbin, Point(201, 201), Point(400, 400), 0, -1);*/
    for (int i = 0; i < 700; ++i)
    {
        mbin.at<char>(i, i) = 0;
        mbin.at<char>(i, 699 - i) = 0;
    }
    cv::circle(mbin, cv::Point(350, 350), 100, 0, 1);
    //cv::circle(mbin, cv::Point(350, 100), 30, 0, -1);
    cv::imshow("mbin", mbin); cv::waitKey();
    vector<vector<cv::Point> > contours;
    vector<cv::Vec4i> hierarchy;
    findContours(mbin, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE, cv::Point(0, 0));

    Mat drawing = Mat::zeros(mbin.size(), CV_8UC3);
    RNG rng(12345);
    for (size_t i = 0; i< contours.size(); i++)
    {
        Scalar color = Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255));
        drawContours(drawing, contours, (int)i, color, 2, 8, hierarchy, 0, Point());
    }

    /// Show in a window
    namedWindow("Contours", WINDOW_AUTOSIZE);
    imshow("Contours", drawing);
    waitKey();
    return 0;
}


I think it's very important since we often use this function. And I hope that function findContours provide a optional parameter to use  8-connected neighbours or 4-connected neighbours methods as users' need.
Thank you very much.
```
## History
##### enpe enpe on 2015-07-12 19:42

```
Your description does not exactly match the example (you speak of only diagonals, your example draws a more elaborate pattern, cf. screenshots below).

A fully working version of your example can be found here: https://gist.github.com/89630565044c87198100.git

The black borders which separate the white areas in your mask are very thin. I am not sure, if the "algorithm":http://docs.opencv.org/trunk/d0/de3/citelist.html#CITEREF_Suzuki85 of @findContours@ designed for the case you describe. In my version of your example if you set the @lineWidth = 2@ the algorithm behaves as expected.

So, I am not sure the case you describe qualifies as a bug. Maybe it's rather a missing feature.

!00_mask.png!
!01_mask_magnified.png!
!02_contours.png!
!03_contours_magnified.png!

-   File 01_mask_magnified.png added
-   File 02_contours.png added
-   File 03_contours_magnified.png added
-   File 00_mask.png added
```