1

I am using the exact same steps to find the contours of an image but I am getting two different results in Opencv 2.4.8 and Opencv 3.2! Anybody knows why? Here is the procedure:

std::vector<std::vector<cv::Point> > contours;
    std::vector<cv::Vec4i> hierarchy;

    cv::imwrite("binImageInB.jpg", binImageIn);

    // find contour of the binary image 
    cv::findContours( binImageIn, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, cv::Point(0, 0) ); // Find the contours in the image   // save

    cv::imwrite("binImageIn.jpg", binImageIn);

The input image is:

Input Image

The output when using opencv 2.4.8:

Output Opencv2

And the output when using Opencv3.2:

enter image description here

Samer
  • 1,923
  • 3
  • 34
  • 54

1 Answers1

1

The documentation for 2.4.x mentions:

Note: Source image is modified by this function.


The documentation for 3.3.1 mentions:

Since opencv 3.2 source image is not modified by this function.


In general, you use the contours and hierarchy output parameters. Since the later versions no longer modify the input image, I'd consided that a side effect, which was not intended to be useful.

Dan Mašek
  • 17,852
  • 6
  • 57
  • 85
  • This is confusing...I am using 3.2 and in the documentation, it does not mention anything is the input image is changed or not https://docs.opencv.org/3.2.0/d3/dc0/group__imgproc__shape.html#ga17ed9f5d79ae97bd4c7cf18403e1689a – Samer Jan 09 '18 at 00:12
  • @Samer You're right. It seems they forgot to add that info to the documentaion comments in 3.2 and [fixed it later](https://github.com/opencv/opencv/commit/e6f27240d5e5fc49f9d079a34abaccf2bee72654). – Dan Mašek Jan 09 '18 at 01:24