public void onDestroy() {
   super.onDestroy();
   Log.i(TAG, "on destory");
   if (mOpenCvCameraView != null) {
     mOpenCvCameraView.disableView();
   }
   xface.destroryFacedetect();
 }
 @Override
 public void onPause() {
   super.onPause();
   Log.i(TAG, "on pause and finish!");
   if (mOpenCvCameraView != null) {
     mOpenCvCameraView.disableView();
   }
   xface.destroryFacedetect();
   SignupCameraActivity.this.finish(); //
 }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_signupcamera);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    name = getIntent().getStringExtra("name");
    userid = getIntent().getIntExtra("userid", -1);

    Log.i(TAG, "name = " + name + " && userid = " + userid);
    btn_camera_ok = (Button) findViewById(R.id.btn_camera_ok);
    btn_camera_takepic = (Button) findViewById(R.id.btn_camera_takepic);

    // / face detection!
    // xface = new XFaceLibrary();// hujiawei
    xface = CommonUtil.xFaceLibrary;
    xface.initFacedetect(CommonUtil.LBPCASCADE_FILEPATH, 0);
    // / face detection!

    mOpenCvCameraView = (SignupCameraView) findViewById(R.id.cv_camera_signup);
    mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
    mOpenCvCameraView.setCvCameraViewListener(this);
    mOpenCvCameraView.enableView();
  }
 public void onCameraViewStopped() {
   Log.i(TAG, "camera view stop");
   mGray.release();
   mRgba.release();
   xface.stopFacedetect();
 }
 public void onCameraViewStarted(int width, int height) {
   Log.i(TAG, "camera view start");
   mGray = new Mat();
   mRgba = new Mat();
   xface.startFacedetect();
 }