2016-01-17 69 views
0

我試圖初始化openCv以便使用相機。該庫被成功初始化,但是當我試圖初始化openCc它返回這個錯誤:無法啓動服務意圖:initOpenCV

01-17 14:19:24.606 8747-8747/com.pettracker.objecttracker E/OpenCV could not be loaded!: CameraTest::CameraPreview 
01-17 14:19:24.606 1267-1476/system_process W/ActivityManager: Unable to start service Intent { act=org.opencv.engine.BIND pkg=org.opencv.engine } U=0: not found 
01-17 14:19:24.606 1267-1278/system_process W/ActivityManager: Unbind failed: could not find connection for [email protected] 

我想使用OpenCV庫使用相機顏色跟蹤。代碼說明如下:

public CameraPreview(ICameraPreviewCallback context, IFrameProcessor frameProcessor) { 
     super((Context)context); 
     mContext = context; 
     System.out.println(mContext); 
     mFrameProcessor = frameProcessor; 
     if (!loadOpenCV()) { 
      Log.e("OpenCV could not be loaded!", TAG); 
     } 
    } 


private boolean loadOpenCV() { 
    return OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_2, (Context)mContext, this); 
} 

另外,我已經修改initOpenCv,這樣我就不會碰上意圖隱含調用,代碼如下所示:

public static boolean initOpenCV(String Version, final Context AppContext, 
     final LoaderCallbackInterface Callback) 
{ 
    AsyncServiceHelper helper = new AsyncServiceHelper(Version, AppContext, Callback); 
    Intent intent = new Intent("org.opencv.engine.BIND"); 
    intent.setPackage("org.opencv.engine"); 
    if (AppContext.bindService(intent, 
      helper.mServiceConnection, Context.BIND_AUTO_CREATE)) 
    { 
     return true; 
    } 
    else 
    { 
     AppContext.unbindService(helper.mServiceConnection); 
     InstallService(AppContext, Callback); 
     return false; 
    } 
} 

什麼可能是這個錯誤的原因?我該如何解決它?

回答

0

看來您已經使用了OpenCv Static Initilization。 有複製項目目錄的本機庫 你可以看看本教程here

//try useing this code for initilization of OpenCv insted of yours. 
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) { 
    @Override 
    public void onManagerConnected(int status) { 
     switch (status) { 
     case LoaderCallbackInterface.SUCCESS: { 
      Log.i(TAG, "OpenCV loaded successfully"); 

     } 
      break; 
     default: { 
      super.onManagerConnected(status); 
     } 
      break; 
     } 
    } 
}; 

@Override 
public void onResume() { 
    super.onResume(); 
    if (!OpenCVLoader.initDebug()) { 
     Log.d(TAG, 
       "Internal OpenCV library not found. Using OpenCV Manager for initialization"); 
     OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, 
       mLoaderCallback); 
    } else { 
     Log.d(TAG, "OpenCV library found inside package. Using it!"); 
     mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS); 
    } 
} 
+0

上傳我的項目代碼錯誤的片段中,正確的版本是在我的上述問題的編輯後的版本說明我修改了錯誤來澄清。另外,我已經在我的項目中添加了本地庫。 –

+0

我使用OpenCVLoader.initAsync()爲您編輯了答案,還有一件事您不需要添加本機庫。你只需要從Play商店下載opencv管理器 –

+0

非常感謝你,我在我的模擬器上下載了最新版本的openCv管理器,一切都很順利。 –

相關問題