Returning Mat object from native code to java in OpenCV

前端 未结 2 841
庸人自扰
庸人自扰 2020-12-03 02:04

I have an OpenCV Android app. Most of its code is in Java but I have one function that is in C. The function gets a Mat object and returns a new one.

My question is

2条回答
  •  时光说笑
    2020-12-03 02:41

    in C++

    jlong funC(){
    Mat *mat = new Mat();
    //...
    return (jlong)mat;
    }
    

    in java:

    long = addr;// addr is return from c method funC()
    Mat mat = new Mat(addr);
    

    Attention: You must new Mat() in C,if you code is : Mat mat();mat object memory will be collect when funC() end.

提交回复
热议问题