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
@Override
public void onResume() {
super.onResume();
//OpenCVLoader.initAsync(OpenCVLoader.OpenCV_VERSION_2_4_3, this, mLoaderCallback);//
}
<3>修改FdActivity.java的OnCreate()方法
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);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值