UnsatisfiedLinkError: n_Mat while using opencv2.4.3 with android 4.0

南楼画角 提交于 2019-11-28 23:55:22

its good that someone prompted me to post my answer elaborately. so here i am posting the solution of my question :

private BaseLoaderCallback mOpenCVCallBack = new BaseLoaderCallback(this) {
     @Override
     public void onManagerConnected(int status) {
       switch (status) {
           case LoaderCallbackInterface.SUCCESS:
           {
              Log.i(TAG, "OpenCV loaded successfully");
              startDisplay();

           } break;


           default:
           {
               super.onManagerConnected(status);
           } break;
         }
      }
 };

    @Override
    protected void onCreate(Bundle savedInstanceState) {


         super.onCreate(savedInstanceState);
         Log.i(TAG, "Trying to load OpenCV library");
         if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mOpenCVCallBack))
         {
           Log.e(TAG, "Cannot connect to OpenCV Manager");
         }
         else{ Log.i(TAG, "opencv successfull"); 
         System.out.println(java.lang.Runtime.getRuntime().maxMemory()); }
         setContentView(R.layout.frameview);
    }

The problem behind this error is that we are calling opencv dependent function(for example: Mat()) before opencv initialization so its showing error. So you can solve it if you put your opencv function in onManagerConnected() like this :

Log.i(TAG, "OpenCV loaded successfully");
startDisplay();

here, startDisplay() contains my Mat() initialization. The problem is when we start an app then oncreate() function executes first and after that opencv is loaded, so if you put your opencv function in oncreate() then it will show error as opencv is not yet loaded.

I hope this will solve your problem. Best of luck... Stackoverflow Rocks!!! :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!