Example usage for org.opencv.imgproc Imgproc Laplacian

List of usage examples for org.opencv.imgproc Imgproc Laplacian

Introduction

In this page you can find the example usage for org.opencv.imgproc Imgproc Laplacian.

Prototype

public static void Laplacian(Mat src, Mat dst, int ddepth) 

Source Link

Usage

From source file:uk.ac.horizon.artcodes.process.BlurDetectionFilter.java

License:Open Source License

@Override
public void process(ImageBuffers buffers) {
    Mat greyImage = buffers.getImageInGrey();

    Mat dst = new Mat();

    long start = System.currentTimeMillis();

    int roiSize = Math.min(greyImage.rows(), greyImage.cols()) / 2;
    Imgproc.Laplacian(greyImage.submat(
            new Rect((greyImage.cols() - roiSize) / 2, (greyImage.rows() - roiSize) / 2, roiSize, roiSize)),
            dst, CvType.CV_16S);/*from  ww  w  .  j a v a2s .co  m*/
    MatOfDouble mean = new MatOfDouble();
    MatOfDouble stdDev = new MatOfDouble();
    Core.meanStdDev(dst, mean, stdDev);

    long end = System.currentTimeMillis();

    //Log.i("STDDEV", "StdDev: "+Math.pow(stdDev.get(0,0)[0],2)+ " (took: " + (end-start) + "ms)");

    double blurScore = Math.pow(stdDev.get(0, 0)[0], 2);

    /*
    Mat overlay = buffers.getOverlay();
    String text = "b.score: " + (int)blurScore + " ("+(end-start)+"ms)";
    int y = overlay.rows()-50;
    int x = 50;
    Imgproc.putText(overlay, text, new Point(x,y), Core.FONT_HERSHEY_SIMPLEX, 1, new Scalar(0,0,0,0), 5);
    Imgproc.putText(overlay, text, new Point(x,y), Core.FONT_HERSHEY_SIMPLEX, 1, new Scalar(255,255,255,255), 3);
    */

    // if image is blurry
    if (blurScore <= 100) {
        // tell camera to focus
        Log.i("FOCUS", "Blur detector requesting auto focus with b.score of " + (int) blurScore);
        this.cameraFocusControl.focus(new Runnable() {
            @Override
            public void run() {

            }
        });
    }

}