我需要将我的一个资源图片转换为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)
这很烦人。
答案 0 :(得分:2)
哦,你不能使用任何与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.
}