title: Looping through OpenCV Mat in Java bindings
body: <p>I am trying to convert a C++ method from a <a href="https://stackoverflow.com/a/15699181/131194">previous answer</a> I received using OpenCV to Java using OpenCV Java bindings</p>
  
  <p>C++ code:</p>
  
  <pre><code>cv::Mat gray;
  cv::Mat element = cv::getStructuringElement(cv::MORPH_CROSS,
                                         cv::Size(2 * erosion_size + 1, 2 * erosion_size + 1),
                                         cv::Point(erosion_size, erosion_size) );
  cv::erode(gray, gray, element);
   // Scan the image searching for points and store them in a vector
  std::vector&lt;cv::Point&gt; points;
  cv::Mat_&lt;uchar&gt;::iterator it = gray.begin&lt;uchar&gt;();
  cv::Mat_&lt;uchar&gt;::iterator end = gray.end&lt;uchar&gt;();
  for (; it != end; it++)
  {
      if (*it) 
          points.push_back(it.pos()); 
  }
  </code></pre>
  
  <p>I can't figure out how to loop through the <code>gray</code> variable as they are in C code. Below is what I've got so far:</p>
  
  <p>Java Code:</p>
  
  <pre><code>Mat gray = new Mat();
  Mat element = Imgproc.getStructuringElement(
                  Imgproc.MORPH_CROSS, new Size(2 * erosion_size + 1, 2 * erosion_size + 1), new Point(erosion_size, erosion_size)
          );
  Imgproc.erode(img, gray, element);
  List &lt;Point&gt; p = new ArrayList&lt;Point&gt;();
  //How to loop through the gray variable?
  </code></pre>
  
  <p>I went through the <a href="http://docs.opencv.org/java/org/opencv/core/Mat.html" rel="nofollow noreferrer">API's</a> and it seems that <code>Mat</code> does have methods for getting <code>rows</code> and <code>cols</code> but I can't call <code>Iterator</code> on anything..</p>