OpenCV 集成遇到的問(wèn)題
一.導(dǎo)入集成
官網(wǎng)下載android資源包含samples 和sdk
以sdk整體當(dāng)做一個(gè)library導(dǎo)入到項(xiàng)目中
網(wǎng)上好多例子說(shuō)以java文件夾當(dāng)做一個(gè)library試了試會(huì)報(bào)錯(cuò)比較疑惑為什么這么說(shuō)因?yàn)橘Y源里面的samples也是以sdk整體最為library的
-
Package not found錯(cuò)誤
原因 : 加載載libs失敗導(dǎo)致的
-
創(chuàng)建Mat對(duì)象報(bào)錯(cuò)
java.lang.UnsatisfiedLinkError: No implementation found for long org.opencv.core.Mat.n_Mat() (tried Java_org_opencv_core_Mat_n_1Mat and Java_org_opencv_core_Mat_n_1Mat__) at org.opencv.core.Mat.n_Mat(Native Method) at org.opencv.core.Mat.<init>(Mat.java:23)
原因 : 因?yàn)榈膸?kù)還沒(méi)有加載就調(diào)用了本地方法
解決方法 : 按照官方demo中的解決方法 在執(zhí)行onResume()手動(dòng)初始化含數(shù)庫(kù)
@Override
public void onResume() { //進(jìn)行手動(dòng)初始化操作
super.onResume();
if (!OpenCVLoader.initDebug()) {
Log.e("TAG", "Internal OpenCV library not found. Using OpenCV Manager for initialization");
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback);
} else {
Log.e("TAG", "OpenCV library found inside package. Using it!");
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
}
}
//初始化回調(diào)函數(shù)
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
Log.e("TAG", "OpenCV loaded successfully");
//-----------相關(guān)操作-----------
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
項(xiàng)目擱置...