Java Code Examples for org.opencv.core.Core.convertScaleAbs()

The following are Jave code examples for showing how to use convertScaleAbs() of the org.opencv.core.Core class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MOAAP   File: MainActivity.java   View Source Code Vote up 7 votes
void Sobel() {
    Mat grayMat = new Mat();
    Mat sobel = new Mat(); //Mat to store the final result

    //Matrices to store gradient and absolute gradient respectively
    Mat grad_x = new Mat();
    Mat abs_grad_x = new Mat();

    Mat grad_y = new Mat();
    Mat abs_grad_y = new Mat();

    //Converting the image to grayscale
    Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);

    //Calculating gradient in horizontal direction
    Imgproc.Sobel(grayMat, grad_x, CvType.CV_16S, 1, 0, 3, 1, 0);

    //Calculating gradient in vertical direction
    Imgproc.Sobel(grayMat, grad_y, CvType.CV_16S, 0, 1, 3, 1, 0);

    //Calculating absolute value of gradients in both the direction
    Core.convertScaleAbs(grad_x, abs_grad_x);
    Core.convertScaleAbs(grad_y, abs_grad_y);

    //Calculating the resultant gradient
    Core.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 1, sobel);

    //Converting Mat back to Bitmap
    Utils.matToBitmap(sobel, currentBitmap);
    imageView.setImageBitmap(currentBitmap);
}
 
Example 2
Project: OptimizedImageEnhance   File: FeatureWeight.java   View Source Code Vote up 5 votes
public static Mat LaplacianContrast(Mat img) {
	Mat laplacian = new Mat();
	Imgproc.Laplacian(img, laplacian, img.depth());
	//Imgproc.Laplacian(img, laplacian, img.depth(), 3, 1, 0);
	Core.convertScaleAbs(laplacian, laplacian);
	return laplacian;
}
 
Example 3
Project: ImageEnhanceViaFusion   File: WeightCalculate.java   View Source Code Vote up 5 votes
public static Mat LaplacianContrast(Mat img) {
	Mat laplacian = new Mat();
	Imgproc.Laplacian(img, laplacian, img.depth());
	//Imgproc.Laplacian(img, laplacian, img.depth(), 3, 1, 0);
	Core.convertScaleAbs(laplacian, laplacian);
	return laplacian;
}
 
Example 4
Project: MOAAP   File: MainActivity.java   View Source Code Vote up 5 votes
void HarrisCorner() {
    Mat grayMat = new Mat();
    Mat corners = new Mat();

    //Converting the image to grayscale
    Imgproc.cvtColor(originalMat, grayMat, Imgproc.COLOR_BGR2GRAY);

    Mat tempDst = new Mat();
    //finding contours
    Imgproc.cornerHarris(grayMat, tempDst, 2, 3, 0.04);

    //Normalizing harris corner's output
    Mat tempDstNorm = new Mat();
    Core.normalize(tempDst, tempDstNorm, 0, 255, Core.NORM_MINMAX);
    Core.convertScaleAbs(tempDstNorm, corners);

    //Drawing corners on a new image
    Random r = new Random();
    for (int i = 0; i < tempDstNorm.cols(); i++) {
        for (int j = 0; j < tempDstNorm.rows(); j++) {
            double[] value = tempDstNorm.get(j, i);
            if (value[0] > 150)
                Imgproc.circle(corners, new Point(i, j), 5, new Scalar(r.nextInt(255)), 2);
        }
    }

    //Converting Mat back to Bitmap
    Utils.matToBitmap(corners, currentBitmap);
    imageView.setImageBitmap(currentBitmap);
}