简体   繁体   English

无法在JNI本机代码openCv中使用cv :: imwrite保存Mat图像

[英]unable to save Mat image with cv::imwrite in a JNI native code openCv

I have a problem in my native code because in my c ++ code I can not save the images I receive from the JAVA part. 我的本机代码有问题,因为在我的C ++代码中,我无法保存从JAVA部件收到的图像。

I tried using cv::imwrite but the image is never saved in the path and in the corresponding folder. 我尝试使用cv::imwrite但是图像从未保存在路径和相应的文件夹中。

My JNI code is as follows: 我的JNI代码如下:

extern "C"{
    JNIEXPORT jintArray JNICALL Java_com_example_testNativeCode_DisplayImage_FindFeatures(JNIEnv* env, jclass obj, jintArray bufImg, jint w, jint h){

    jint *cbuf;
    cbuf = env->GetIntArrayElements(bufImg, 0);

    if(cbuf==NULL){
       return 0;
    }

    cv::Mat mImg(h,w,CV_8UC4, (unsigned char*)cbuf);

    cv::imwrite("../SaveImage/img.png", mImg);
    }
}

I use android studio 2.3.3 and OpenCv 3.1.0. 我使用android studio 2.3.3和OpenCv 3.1.0。 I put in the manifest: 我输入清单:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

I want to know if it was possible to record an image with cv::imwrite ? 我想知道是否可以用cv::imwrite记录图像? How else can I do to save it? 我还能怎么做保存它?

I am experiencing the same problem,but i solve it by this steps: 我遇到了同样的问题,但是我可以通过以下步骤解决:

1.request permission 1.请求权限

 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

2.Manually open the permission switch 2.手动打开权限开关

3.Close app and clear task 3.关闭应用程序并清除任务

4.Open your project app and try again,it it working to me. 4.打开您的项目应用程序,然后重试,它对我有用。

If it is not working for you,uninstall and reinstall app,and repeat the above steps 如果它不适合您,请卸载并重新安装应用程序,然后重复上述步骤

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM