2016-08-01 29 views
2

我需要使用OpenCV 3.1.0分配相当大的矩阵。我运行下面的代码与-Djava.library.path = $ MODULE_DIR $ \ OpenCV的\ 310个\ WINDOWS \ 64 \ -Xmx8g参数:java opencv本地库和内存限制

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); 
    } 
} 

第一个测试工作,因为秒罚球(行:iMatrix.put(0,0,数据)

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) 

它是一个OpenCV的或本地库的使用限制?有没有解决此类问题的方法?

编辑:附完整的代码和堆栈跟踪

+0

哪条线发生异常? –

+0

附带完整代码和堆栈跟踪。 – fatman

+0

好的,这个例外似乎仍然是一个Java异常:引入一些中等大小的矩阵,看它失败的地方(所以太大的限制是什么),然后增加Java内存(xmx)以查看限制太大的转变。那么你知道它是Java还是OpenCV是限制因素 –

回答

2

这是OpenCV的问题。有一些signed int类型的变量作为矩阵大小,超过了我的巨大数组。检查源代码:link。解决方法是创建较小的Mats列表并使用vconcat(slices,result)函数将它们加入。