首页 文章

无法将图片加载到Mat opencv中

提问于
浏览
2

我想在Android opencv上使用Mat类加载图像,但我有一些错误 . 我在我的项目上添加了库 . 我的代码:私有CameraBridgeViewBase mOpenCvCameraView;
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this){@ Overver public void onManagerConnected(int status){switch(status){case LoaderCallbackInterface.SUCCESS:{Log.i(TAG,"OpenCV loaded successfully"); mOpenCvCameraView.enableView();打破default:{super.onManagerConnected(status);打破}};

@Override
public void onResume()
{
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback);
}



 @Override
 public void onCreate(Bundle savedInstanceState) {
     Log.i(TAG, "called onCreate");
     super.onCreate(savedInstanceState);
     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
     setContentView(R.layout.activity_main);
     mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.HelloOpenCvView);
     mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
     mOpenCvCameraView.setCvCameraViewListener(this);
     if (!OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_9, this, mLoaderCallback))
     {
       Log.e(TAG, "Cannot connect to OpenCV Manager");
     }
     else
         Log.i(TAG, "Load it"); 

     Mat Image = Highgui.imread("/mnt/sdcard/1.jpg");

 }

 @Override
 public void onPause()
 {
     super.onPause();
     if (mOpenCvCameraView != null)
         mOpenCvCameraView.disableView();
 }

 public void onDestroy() {
     super.onDestroy();
     if (mOpenCvCameraView != null)
         mOpenCvCameraView.disableView();
 }

 public void onCameraViewStarted(int width, int height) {
 }

 public void onCameraViewStopped() {
 }


public Mat onCameraFrame(CvCameraViewFrame inputFrame) {  
    return inputFrame.rgba();
}

日志:

enter image description here

谢谢

1 回答

  • 2

    你不能在onCreate()中使用任何opencv代码

    所以's with opencv'的本机代码尚未加载,您必须等待,直到mLoaderCallback完成 .

    所以,将Mat上的任何操作移到onCameraViewStarted()

相关问题