0

我需要将我的一张资源图片从 OpenCV 转换为 Mat,但使用此代码时应用程序崩溃:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cmc7);
    Mat myMat = new Mat();
    Utils.bitmapToMat(mBitmap, myMat);

    setContentView(R.layout.main);
}

只要我没有 bitmapToMat 线,一切都很好。

FATAL EXCEPTION: main    
?:??: W/?(?): java.lang.UnsatisfiedLinkError: Native method not found: org.opencv.core.Mat.n_Mat:(III)J
?:??: W/?(?): org.opencv.com.Mat.n_Mat(Native Method)

这很烦人。

4

1 回答 1

1

哦,在经理完成加载之前,您不能使用任何与 opencv 相关的代码;)

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        if (status == LoaderCallbackInterface.SUCCESS ) {
            // now we can call opencv code !

            Bitmap mBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.cmc7);
            Mat myMat = new Mat();
            Utils.bitmapToMat(mBitmap, myMat);

        } else {
            super.onManagerConnected(status);
        }
    }
};

@Override
public void onResume() {;
    super.onResume();
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_5,this, mLoaderCallback);
    // you may be tempted, to do something here, but it's *async*, and may take some time,
    // so any opencv call here will lead to unresolved native errors.
}
于 2013-07-25T14:17:02.807 回答