安卓& OpenCV:Utils.bitmapToMat崩溃 [英] Android & OpenCV : Utils.bitmapToMat crashes

查看:547
本文介绍了安卓& OpenCV:Utils.bitmapToMat崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to convert one of my ressource picture to a Mat from OpenCV, but the app crashes while using this code :

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行,一切都很好.

As long as I do not have the bitmapToMat line, everything is fine.

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)

这很烦人.

推荐答案

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

oh, you cannot use any opencv - related code, until the manager finished loading ;)

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.
}

这篇关于安卓& OpenCV:Utils.bitmapToMat崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆