コード例 #1
0
ファイル: OpenCVActivity.java プロジェクト: prefanatic/TheiaC
  @Override
  public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    // Imgproc.bilateralFilter(inputFrame.gray(), inputFrame.rgba(), 9, 75, 75);

    /* if (captureBackground) {
        captureBackground = false;
        background = new Mat(inputFrame.gray(), new Rect(0, 0, inputFrame.gray().width(), inputFrame.gray().height()));
    }

    if (background == null) {
        return inputFrame.rgba();
    }


    return background;*/

    background = inputFrame.gray();

    Imgproc.cvtColor(background, mRgb, Imgproc.COLOR_GRAY2RGB);

    /*Imgproc.erode(mFGMask, mFGMask, new Mat());
    Imgproc.dilate(mFGMask, mFGMask, new Mat());

    Imgproc.findContours(mFGMask, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_NONE);
    Imgproc.drawContours(mRgb, contours, -1, new Scalar(255, 0, 0), 2);*/

    return mRgb;
  }
コード例 #2
0
  @Override
  public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {

    mRgba = inputFrame.rgba();
    Imgproc.cvtColor(mRgba, grayScaleImage, Imgproc.COLOR_RGBA2RGB);

    MatOfRect faces = new MatOfRect();

    // detect faces
    if (cascadeClassifier != null) {
      cascadeClassifier.detectMultiScale(
          grayScaleImage,
          faces,
          1.1,
          2,
          2,
          new Size(absoluteFaceSize, absoluteFaceSize),
          new Size());
    }

    Rect[] facesArray = faces.toArray();
    for (int i = 0; i < facesArray.length; i++)
      Core.rectangle(mRgba, facesArray[i].tl(), facesArray[i].br(), new Scalar(0, 255, 0, 255), 3);

    if (facesArray.length > 0) {
      facesInASecond.add(true);
    } else {
      facesInASecond.add(false);
    }

    return mRgba;
  }