title: OpenCV Draw Contours in JAVA (Android)
body: <p>I'm trying to draw the contour of an image in JAVA (Android) but it doesn't seem to do anything (the function doesn't draw anything) Here's the code:</p>
  
  <pre><code>  public Mat contours(Mat mat)
      {
          ArrayList&lt;MatOfPoint&gt; contours = new ArrayList&lt;MatOfPoint&gt;();
          Mat hierarchy = new Mat();
  
          Mat balele = new Mat();
          mat.convertTo(balele, CvType.CV_32SC1);
          // find contours:
          Imgproc.findContours(balele, contours, hierarchy, Imgproc.RETR_FLOODFILL, Imgproc.CHAIN_APPROX_SIMPLE);
  
  
          Mat source = new Mat(balele.size(), balele.type());
          for (int contourIdx = 0; contourIdx &lt; contours.size(); contourIdx++)
          {
              Imgproc.drawContours(source, contours, contourIdx, new Scalar(0,0,255), -1);
          }
  
          return source;
      }
  </code></pre>
  
  <p>The mat image is in binary format already when we pass it to the method.</p>
  
  <p>Do you detect any error ?</p>
  
  <p>UPDATE:
  i updated the code, it looks like this:</p>
  
  <p>public Mat contours(Mat mat)
  {</p>
  
  <pre><code>ArrayList&lt;MatOfPoint&gt; contours = new ArrayList&lt;MatOfPoint&gt;();
  Mat hierarchy = new Mat();
  
  // find contours:
  Imgproc.findContours(mat, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE);
  System.out.println(contours.size() + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
  
  Mat source = new Mat();
  for (int contourIdx = 0; contourIdx &lt; contours.size(); contourIdx++)
  {
      Imgproc.drawContours(source, contours, contourIdx, new Scalar(0,0,255), -1);
  }
  
  return source;
  </code></pre>
  
  <p>}</p>
  
  <p>Results:
  <a href="https://i.stack.imgur.com/Ny5T1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ny5T1.jpg" alt="ORIGINAL PICTURE"></a></p>
  
  <p><a href="https://i.stack.imgur.com/i9UB7.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/i9UB7.jpg" alt="FINAL PICTURE"></a></p>
  
  <p>Im still not getting all of the contour and im getting a light white color. Any idea of a correction ?</p>