@Override
  protected void onPostExecute(Face[] faces) {
    if (mWaitDialog != null) {
      mWaitDialog.dismiss();
    }
    Paint paint = getPaint();
    String mark = "★";
    FontMetrics fontMetrics = paint.getFontMetrics();
    // 小数点切り上げ
    int textWidth = (int) FloatMath.ceil(paint.measureText(mark));
    // http://wikiwiki.jp/android/?%A5%C6%A5%AD%A5%B9%A5%C8%A4%CE%C9%C1%B2%E8(FontMetrics) 参照
    int textHeight =
        (int)
            FloatMath.ceil(
                Math.abs(fontMetrics.ascent)
                    + Math.abs(fontMetrics.descent)
                    + Math.abs(fontMetrics.leading));
    if (mFaceNum > 0) {
      for (Face face : faces) {
        if (face == null) {
          continue;
        }
        PointF point = new PointF();
        // 目と目の間の座標を取得
        face.getMidPoint(point);
        float disH = face.eyesDistance() / 2;
        // 右目
        float leftX = point.x - disH - (textWidth / 2);
        float leftY = point.y + (textHeight / 2);
        mCanvas.drawText(mark, leftX, leftY, paint);

        // 左目
        float rightX = point.x + disH - (textWidth / 2);
        float rightY = point.y + (textHeight / 2);
        mCanvas.drawText(mark, rightX, rightY, paint);
        Log.d("------pose-----", String.valueOf(face.pose(Face.EULER_X)));
      }
    }

    mCallback.onPostExcute(mEditBitmap);
    super.onPostExecute(faces);
  }
Пример #2
0
  void doFacedetect(byte[] data, Camera camera) {
    long start = System.currentTimeMillis();
    Bitmap bmp = CameraUtil.yuvimage2Bitmap(data, camera);
    Matrix matrix = new Matrix();
    matrix.postRotate(270);
    matrix.postScale(-1, 1);
    Bitmap tmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);
    bmp.recycle();
    DisplayMetrics dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    int heightScreen = dm.heightPixels;
    int widthScreen = dm.widthPixels;
    Bitmap tmp1 = Bitmap.createScaledBitmap(tmp, widthScreen, heightScreen, true);
    tmp.recycle();
    RectF rect = mFaceView.getRect();
    Bitmap tmp2 =
        Bitmap.createBitmap(
            tmp1,
            (int) rect.left,
            (int) rect.top,
            (int) (rect.right - rect.left),
            (int) (rect.bottom - rect.top));
    tmp1.recycle();
    Bitmap picture = tmp2.copy(Bitmap.Config.RGB_565, true);
    tmp2.recycle();

    int N_MAX = 1;
    FaceDetector faceDetector = new FaceDetector(picture.getWidth(), picture.getHeight(), N_MAX);
    Face[] faces = new Face[N_MAX];
    faceDetector.findFaces(picture, faces);

    for (Face f : faces) {
      try {
        PointF midPoint = new PointF();
        f.getMidPoint(midPoint);
        if (f.confidence() < 0.4) return;
        findFaceCount++;
        mFaceView.setFaceParameters(midPoint, f.eyesDistance());
        if (findFaceCount == 3) {
          showCapture();
          findFaceCount = 0;
        }
        if (modeSwitch.isChecked()) {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          picture.compress(CompressFormat.JPEG, 100, out);
          byte[] picBytes = out.toByteArray();
          Intent intent = new Intent(RegistCameraActivity.this, DisplayActivity_.class);
          intent.putExtra("picture", picBytes);
          intent.putExtra("isRegist", true);
          intent.putExtra("auto", true);
          intent.putExtra("currentCamera", CURRENT_CAMERA);
          startActivity(intent);
        }

        //				System.out.println("YOU:"+midPoint);
      } catch (Exception e) {
        // TODO Auto-generated catch block
        //				e.printStackTrace();
        mFaceView.setFaceParameters(null, 0);
        mFaceView.invalidate();
        findFaceCount = 0;
      } finally {
        picture.recycle();
      }
    }

    long end = System.currentTimeMillis();
    System.out.println("耗时:" + (end - start) + " ms");

    Timer timer = new Timer();
    TimerTask task =
        new TimerTask() {

          @Override
          public void run() {
            clearEyeCircle();
          }
        };
    timer.schedule(task, 200);
  }