2

I need to allocate rather large matrix using OpenCV 3.1.0. I'm running following code with -Djava.library.path=$MODULE_DIR$\opencv\310\windows\x64\ -Xmx8g arguments:

public class MatTest extends BaseTest {

  static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME);}

  @Test
  public void tooBig() throws IOException {
    float[] data = new float[13320*67294];
    Mat iMatrix = new Mat(13320, 67294, CvType.CV_32FC1);
    iMatrix.put(0, 0, data); //exception here
  }

  @Test
  public void medium() throws IOException {
    float[] data = new float[13918*13240];
    Mat iMatrix = new Mat(13918, 13240, CvType.CV_32FC1);
    iMatrix.put(0, 0, data);
  }
}

The first test works, since the seconds throws (line: iMatrix.put(0, 0, data))

java.lang.Exception: unknown exception

  at org.opencv.core.Mat.nPutF(Native Method)
  at org.opencv.core.Mat.put(Mat.java:953)
  at my.app.MatTest.tooBig(MatTest.java:19)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:497)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
  at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)

Is it a OpenCV or native library usage limitation? Is there a workaround for such issue?

Edited: attached full code and stacktrace

5
  • Which line does the exception occur at? Commented Aug 1, 2016 at 22:08
  • Full code & stacktrace attached. Commented Aug 2, 2016 at 5:53
  • Ok, the exception still seems to be a Java exception: Introduce a few intermediate size matrices, see from which point it fails (so what is really the limit for the too large), then increase Java memory (xmx) to see if the limit for too large shifts. Then you know if it is Java or OpenCV which is the limiting factor Commented Aug 2, 2016 at 15:09
  • 1
    It is OpenCV issue. There are some variables of signed int type as a matrix size which was exceeded by my huge array. link Commented Aug 3, 2016 at 20:53
  • Make it a self answer and I will upvote that: Helpful research:) Commented Aug 3, 2016 at 21:30

1 Answer 1

2

It is OpenCV issue. There are some variables of signed int type as a matrix size which was exceeded by my huge array. Check source code: link. The workaround is to create the list of smaller Mats and join them using vconcat(slices, result) function.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.