Example usage for org.opencv.imgproc Imgproc integral

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

Introduction

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

Prototype

public static void integral(Mat src, Mat sum) 

Source Link

Usage

From source file:karthik.Barcode.MatrixBarcode.java

License:Open Source License

private int[] calcEdgeDensityIntegralImage() {
    // calculates number of edges in the image and returns it as an integral image
    // first set all non-zero gradient magnitude points (i.e. all edges) to 1
    // then calculate the integral image from the above
    // we can now calculate the number of edges in any tile in the matrix using the integral image

    Imgproc.threshold(img_details.gradient_magnitude, img_details.temp_integral, 1, 1, Imgproc.THRESH_BINARY);
    Imgproc.integral(img_details.temp_integral, img_details.temp_integral);

    img_details.temp_integral.get(0, 0, img_details.edgeDensity);

    return img_details.edgeDensity;
}

From source file:karthik.Barcode.MatrixBarcode.java

License:Open Source License

private void calcHistograms() {
    /* calculate histogram by masking for angles inside each bin, thresholding to set all those values to 1
       and then creating an integral image. We can now calculate histograms for any size tile within 
       the original image more efficiently than by using the built in calcHist method which would have to 
       recalculate the histogram for every tile size.
    *//*from w w w. j a  v  a2  s  .co m*/
    Mat target;
    angles = img_details.gradient_direction.clone();
    target = img_details.temp_integral;

    for (int binRange = 1, integralIndex = 0; binRange < 181; binRange += img_details.BIN_WIDTH, integralIndex++) {
        target.setTo(ZERO_SCALAR);

        img_details.gradient_direction.copyTo(angles);
        Core.inRange(img_details.gradient_direction, scalarDict.get(binRange),
                scalarDict.get(binRange + img_details.BIN_WIDTH), mask);
        Core.bitwise_not(mask, mask);
        angles.setTo(ZERO_SCALAR, mask);

        Imgproc.threshold(angles, target, 0, 1, Imgproc.THRESH_BINARY);
        Imgproc.integral(target, target);
        target.get(0, 0, img_details.histIntegralArrays[integralIndex]);
    }

    // there is some problem if the created integral image does not have exactly one channel
    assert (target.channels() == 1) : "Integral does not have exactly one channel";

}