我试图初始化openCv以便使用相机。库已成功初始化,但当我尝试初始化openCc时,它返回此错误:
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 android.os.BinderProxy@b15c6c98
我正在尝试使用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,这样我就不会遇到对intent的隐式调用,代码如下所示:
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 :(得分: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);
}
}