我正在尝试使用OpenCV在Android Studio中加载和显示图像,但它崩溃了。我找不到问题在哪里...... 感谢任何帮助!谢谢!
public class MainActivity2 extends Activity {
private static final String TAG = "Kate : ";
BaseLoaderCallback mOpenCVCallBack;
Mat mRgba;
ImageView imge1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_activity2);
}
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
Log.i(TAG, "OpenCV loaded successfully");
mRgba=new Mat();
load_AND_display();
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
public void load_AND_display() {
//getting ImageView
imge1= (ImageView) findViewById(R.id.img1);
try {
//Loading Image to Mat object
mRgba= Utils.loadResource(this,R.drawable.mako,Highgui.CV_LOAD_IMAGE_COLOR);
} catch (IOException e) {
e.printStackTrace();
}
// create a bitmap:
Bitmap bm = Bitmap.createBitmap(mRgba.cols(), mRgba.rows(),Bitmap.Config.ARGB_8888);
// convert Mat image to bitmap::
Utils.matToBitmap(mRgba, bm);
//setting the image
imge1.setImageBitmap(bm);
}
@Override
public void onResume() {
super.onResume();
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS);
/*OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_6, this, mLoaderCallback);*/
}
这是Logcat:
05-05 15:54:20.323 29948-29948/com.example.myapplication E/art﹕ 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__)
05-05 15:54:20.323 29948-29948/com.example.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.myapplication, PID: 29948
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__)
答案 0 :(得分:1)
使用以下步骤:
$(document).ready(function () {
debugger;
searchParameter = document.getElementById('malzemeKoduInput').value;
$(function () {
$("#malzemeKoduInput").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: "{\"searchParameter\":\" " + request.term + " \"}",
url: "@ViewBag.UrlPath/api/KritikUrunIzleme/KritikUrunMalzemeArama",
dataFilter: function (data) { return data; },
succes: function (data) {
debugger;
//controlUrunAramaList = data.kritikUrunMalzemeAramaList;
console.log(JSON.stringify(data));
response($.map(data, function(item) {
return item;
}))
},
error: function (data) {
console.log(data);
},
minLength: 1
});
}
});
});
});
private val mLoaderCallback: BaseLoaderCallback = object : BaseLoaderCallback(this) {
override fun onManagerConnected(status: Int) {
when (status) {
SUCCESS -> {
Log.e("OpenCV", "OpenCV loaded successfully")
}
else -> {
super.onManagerConnected(status)
}
}
}
}
中,检查天气 OpenCv 是否已加载:onResume()
override fun onResume() {
super.onResume()
if (!OpenCVLoader.initDebug()) {
Log.d(
"OpenCV",
"Internal OpenCV library not found. Using OpenCV Manager for initialization"
)
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback)
} else {
Log.d("OpenCV", "OpenCV library found inside package. Using it!")
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS)
}
}
操作或初始化 Mat 之前——调用:opencv
.....
setContentView(R.layout.activity_main)
OpenCVLoader.initDebug()
.....
这里 val matObject = Mat()
Utils.bitmapToMat(mBitmap, matObject)
是我们要使用的图像的位图,mBitmap
是 Utils.bitmapToMat()
的内置函数在您的代码中,将 drawable 作为位图加载,然后转换为垫子。