从活动中使用 OpenCV 时 Android 崩溃 [英] Android crashes when using OpenCV from activity
问题描述
我是 OpenCV 的新手,但我相信按照此页面上的说明我已经正确设置了所有内容 link
I am new to OpenCV, but I believe that I have everything set up correctly by following the instructions on this page link
基本上,每当我尝试从 Activity 访问 OpenCV 库中的任何内容时,我的应用都会崩溃.
Basically, my app crashes whenever I try to access anything from the OpenCV library from activity.
以下代码片段为例:
Mat src = new Mat(100, 100, CvType.CV_8UC4);
这里我只是想初始化一个矩阵.当我调试代码时,它进入 Mat.class 文件,然后它会抛出一个Invocation TargetException",说源附件不包含文件 Invocation TargetException.class 的源."
here I'm just trying to initialise a matrix. When I debug the code, it goes into the Mat.class file, then it will throw a 'Invocation TargetException' saying 'The source attachment does not contain the source for the file Invocation TargetException.class.'
我在 Internet 上详尽地搜索了解决方案,但找不到满意的解决方案,而且我已经在这个问题上困扰了数周.如果需要任何进一步的信息,请告诉我.非常感谢!
I have searched for solutions exhaustively on the Internet but couldn't find a satisfactory one and I've been stuck on this issue for weeks. If any further information is required please let me know. Many thanks in advance!
注意:我在最开始调用 OpenCVLoader 并返回 true,并且我从示例 OpenCV 应用程序中提取了以下代码片段:
Note: I call OpenCVLoader at the very beginning and it returns true, and I have the following code snippet taken from the sample OpenCV app:
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS: {
// TODO: test
System.loadLibrary("img_proc_utils");
}
break;
default: {
super.onManagerConnected(status);
}
break;
}
}
};
推荐答案
原来是我的 Android.mk 有问题.我包括了 OPENCV_INSTALL_MODULES:=on,现在一切都像魅力一样:)
It turned out to be a problem with my Android.mk. I included OPENCV_INSTALL_MODULES:=on and everything works like a charm now :)
这篇关于从活动中使用 OpenCV 时 Android 崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!