title: OpenCV convexhull doesn't give correct output
body: <p>This is my input binary image:</p>
  
  <p><img src="https://i.stack.imgur.com/Zpdag.jpg" alt="enter image description here"></p>
  
  <p>Now I want to get its convex hull using OpenCV. For that, I wrote the following code: </p>
  
  <pre><code>cv::Mat input = cv::imread("input.jpg", CV_LOAD_IMAGE_GRAYSCALE);
  cv::vector&lt;cv::vector&lt;cv::Point&gt;&gt; contours;
  cv::vector&lt;cv::Vec4i&gt; hierarchy;
  
  // Find contours
  cv::findContours(input, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
  
  // Find the convex hull
  cv::vector&lt;cv::vector&lt;cv::Point&gt;&gt; hull(contours.size());
  for(int i = 0; i &lt; contours.size(); i++)
  {
      cv::convexHull(cv::Mat(contours[i]), hull[i], false);
  }
  
  cv::Mat drawing = cv::Mat::zeros(input.size(), CV_8UC3);
  cv::Scalar color = cv::Scalar(0, 0, 255);
  for (int j  = 0; j &lt; hull.size(); j++)
  {
      cv::drawContours(drawing, hull, j, color, 1, 8, cv::vector&lt;cv::Vec4i&gt;(), 0, cv::Point());
  }
  
  cv::imshow("Convex hull", drawing);
  cv::waitKey();
  </code></pre>
  
  <p>And this is the output:</p>
  
  <p><img src="https://i.stack.imgur.com/brJLc.jpg" alt="enter image description here"></p>
  
  <p>In Matlab however, when I write the following code:</p>
  
  <pre><code>input = imread('input.jpg');
  [x, y] = find(input);
  k = convhull(x, y);
  plot(y(k), x(k), 'r-', y, x, 'b.');
  </code></pre>
  
  <p>This gives me exactly what I want (the red line represents the convex hull that I want):</p>
  
  <p><img src="https://i.stack.imgur.com/RpHwm.jpg" alt="enter image description here"></p>
  
  <p>So, how can I obtain the same result in OpenCV? What should I've done incorrectly here? Thank you. </p>