gpt4 book ai didi

android - Android和OpenCV:Utils.bitmapToMat崩溃

转载 作者:行者123 更新时间:2023-12-02 17:14:18 25 4
gpt4 key购买 nike

我需要将我的资源图片之一从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)

这很烦人。

最佳答案

哦,在管理器完成加载之前,您不能使用任何与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.
}

关于android - Android和OpenCV:Utils.bitmapToMat崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17860472/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com