2016-01-29 37 views
13

我正在使用OpenCV for adaptiveThreshold。我使用OpenCV的圖像處理代碼是這樣的:找不到實現org.opencv.core.Mat.n_Mat()的錯誤()error使用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); 

但同時宣佈我收到一個錯誤。像:

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,我沒有認清這哪裏碼屬於是here和error.The整個Java類。

我該怎麼做才能消除錯誤?

回答

26

我已經成功地消除了錯誤,並在執行這條線我的應用程序不會崩潰imageMat=new Mat();

的原因錯誤是Android的加載OpenCV4Android library.So我以前調用「的onCreate」方法使用OpenCV的異步初始化使用OpenCVManager。我創建了BaseLoaderCallback之前onCreate方法。而且裏面,我已經宣佈新墊()這樣的:

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
4

初始化OpenCV庫在活動 的onCreate之前添加以下代碼()方法

 static { 
      if (!OpenCVLoader.initDebug()) { 
      // Handle initialization error 
      } 
      } 

將此lib添加到您的項目中:https://github.com/hschott/Camdroid

相關問題