gpt4 book ai didi

android - No implementation found for long org.opencv.core.Mat.n_Mat() 错误使用 OpenCV

转载 作者:IT老高 更新时间:2023-10-28 22:01:37 30 4
gpt4 key购买 nike

我正在为 adaptiveThreshold 使用 OpenCV。我使用 OpenCV 进行图像处理的代码是这样的:

imageMat=new Mat();
Utils.bitmapToMat(bmp, imageMat);
Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_BGR2GRAY);
Imgproc.GaussianBlur(imageMat, imageMat, new Size(3, 3), 0);
Imgproc.adaptiveThreshold(imageMat, imageMat, 255,Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 5, 4);

但我在声明 Mat 时遇到错误:

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:24)
at com.example.pial_pc.instantbookreview.ImageCapture$3.onPictureTaken(ImageCapture.java:105)

由于我是 OpenCV 的新手,我并不清楚这个错误。这段代码所属的整个Java类是here .

我应该怎么做才能消除错误?

最佳答案

我已成功消除错误,并且我的应用在执行此行时不会崩溃 imageMat=new Mat();

错误的原因是Android在加载OpenCV4Android库之前调用了“onCreate”方法。所以我使用了OpenCVManager的OpenCV异步初始化。我在 onCreate 方法之前创建了 BaseLoaderCallback。在里面我已经声明了 new Mat() 像这样:

private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
@Override
public void onManagerConnected(int status) {
switch (status) {
case LoaderCallbackInterface.SUCCESS:
{
Log.i("OpenCV", "OpenCV loaded successfully");
imageMat=new Mat();
} break;
default:
{
super.onManagerConnected(status);
} break;
}
}
};

然后在 onResume() 中,我检查了 OpenCV 库是否已从当前应用程序包中加载和初始化。代码如下:

public void 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);
}
}

我的错误消失了。我完整更新的 java 类是 here .

引用链接:

  1. Async Initialization of OpenCV on Android using OpenCVManager
  2. Tutorial1Activity.java

关于android - No implementation found for long org.opencv.core.Mat.n_Mat() 错误使用 OpenCV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35090838/

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