首页 > 代码库 > Android 和OpenCV整合开发(2)---去除OpenCV Manager包的方法
Android 和OpenCV整合开发(2)---去除OpenCV Manager包的方法
以修改FaceDetection例子工程为例>
- 1,修改makefile【Android.mk】(在jni目录下)
OpenCV_CAMERA_MODULES:=
on
OpenCV_INSTALL_MODULES:=
on
OpenCV_LIB_TYPE:=
SHARED
include ${OpenCVROOT}/sdk/native/jni/OpenCV.mk
2,修改FdActivity.java文件
<1>增加静态函数
static {
Log.i(TAG,"OpenCV library load!");
if (!OpenCVLoader.initDebug()) {
Log.i(TAG,"OpenCV load not successfully");
} else {
System.loadLibrary("detection_based_tracker");// load other libraries
}
}
<2>删除FdActivity.java的OnResume()方法的最后那句,不让它去访问OpenCV Manager<3>修改FdActivity.java的OnCreate()方法@Override public void onResume() { super.onResume();
//OpenCVLoader.initAsync(OpenCVLoader.OpenCV_VERSION_2_4_3, this, mLoaderCallback);//
}
public void onCreate(Bundle savedInstanceState) { Log.i(TAG,"called onCreate"); super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); setContentView(R.layout.face_detect_surface_view);
// add start
try { // load cascade file from application resources InputStream is = getResources().openRawResource(R.raw.lbpcascade_frontalface); File cascadeDir = getDir("cascade", Context.MODE_PRIVATE); mCascadeFile = new File(cascadeDir,"lbpcascade_frontalface.xml"); FileOutputStream os = new FileOutputStream(mCascadeFile); byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = is.read(buffer)) != -1) { os.write(buffer, 0, bytesRead); } is.close(); os.close(); mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath()); if (mJavaDetector.empty()) { Log.e(TAG,"Failed to load cascade classifier"); mJavaDetector = null; } else Log.i(TAG,"Loaded cascade classifier from"+ mCascadeFile.getAbsolutePath()); mNativeDetector = new DetectionBasedTracker(mCascadeFile.getAbsolutePath(), 0);// hujiawei cascadeDir.delete(); } catch (IOException e) { e.printStackTrace(); Log.e(TAG,"Failed to load cascade. Exception thrown:"+ e); }
//add end
mOpenCVCameraView = (CameraBridgeViewBase) findViewById(R.id.fd_activity_surface_view); mOpenCVCameraView.enableView();
// add.
mOpenCVCameraView.setCvCameraViewListener(this); }
Android 和OpenCV整合开发(2)---去除OpenCV Manager包的方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。