title: Get a sub image using opencv Java
body: <p>I have already looked at <a href="https://stackoverflow.com/questions/28337813/how-to-get-sub-image-by-using-opencv-in-java-api">how to get sub image by using OpenCV in java api</a>, but this did not help</p>
  
  <p>I am curious how to create a sub image of a Mat image that I have loaded in from a file. When I run:</p>
  
  <pre><code>crop = img.submat(405, 450, 280, 335);
  </code></pre>
  
  <p>I get :</p>
  
  <pre><code>  OpenCV Error: Assertion failed (m.dims &gt;= 2) in cv::Mat::Mat, file ..\..\..\..\opencv\modules\core\src\matrix.cpp, line 269
  Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: ..\..\..\..\opencv\modules\core\src\matrix.cpp:269: error: (-215) m.dims &gt;= 2 in function cv::Mat::Mat
  ]
      at org.opencv.core.Mat.n_submat_rr(Native Method)
      at org.opencv.core.Mat.submat(Mat.java:2270)
      at Parking.WebCommunications.processImage(WebCommunications.java:54)
      at Parking.WebCommunications.&lt;init&gt;(WebCommunications.java:27)
      at Parking.App.main(App.java:19)
  </code></pre>
  
  <p>I cannot seem to figure out why this is happening. When I run what seems to be a similar piece of code in python on the image it works properly...but I need java to work...</p>
  
  <p>EDIT:</p>
  
  <pre><code>    Range xRange = new Range(405, 450);
      Range yRange = new Range(280, 355);
      Mat crop;
      Mat blur = null;
  
      System.loadLibrary("opencv_java2411");
  
      //Load image from file
      Mat img = Highgui.imread("/Users/\"User name\"/git/SE300/JavaWorkspace/ParkingLotApp/src/main/resources/bottomOpen.JPG");
  
      //LOOP:
          //Crop to the Nth spot: cropN = img[y:y+h, x:x+w]
      System.out.println(img.rows());
      System.out.println(img.cols());
  
          crop = img.submat(405, 450, 280, 335);
  </code></pre>