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

The following are Jave code examples for showing how to use addWeighted() 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.
Example 1
Project: Java-for-Data-Science   File: OpenCVNonMavenExamples.java   Source Code and License Vote up 7 votes
public void sharpenImage() {
        String fileName = "SharpnessExample2.png";
        fileName = "smoothCat.jpg";
        fileName = "blurredText.jpg";
        fileName = "Blurred Text3.jpg";
        try {
//            Not working that well !!!
            Mat source = Imgcodecs.imread(fileName,
                    //                    Imgcodecs.CV_LOAD_IMAGE_COLOR);
                    Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
            Mat destination = new Mat(source.rows(), source.cols(), source.type());
            Imgproc.GaussianBlur(source, destination, new Size(0, 0), 10);
            // The following was used witht he cat
//            Core.addWeighted(source, 1.5, destination, -0.75, 0, destination);
//            Core.addWeighted(source, 2.5, destination, -1.5, 0, destination);
            Core.addWeighted(source, 1.5, destination, -0.75, 0, destination);
            Imgcodecs.imwrite("sharpenedCat.jpg", destination);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
Example 2
Project: MOAAP   File: MainActivity.java   Source Code and License 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 3
Project: Machine-Learning-End-to-Endguide-for-Java-developers   File: OpenCVNonMavenExamples.java   Source Code and License Vote up 6 votes
public void sharpenImage() {
        String fileName = "SharpnessExample2.png";
        fileName = "smoothCat.jpg";
        fileName = "blurredText.jpg";
        fileName = "Blurred Text3.jpg";
        try {
//            Not working that well !!!
            Mat source = Imgcodecs.imread(fileName,
                    //                    Imgcodecs.CV_LOAD_IMAGE_COLOR);
                    Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
            Mat destination = new Mat(source.rows(), source.cols(), source.type());
            Imgproc.GaussianBlur(source, destination, new Size(0, 0), 10);
            // The following was used witht he cat
//            Core.addWeighted(source, 1.5, destination, -0.75, 0, destination);
//            Core.addWeighted(source, 2.5, destination, -1.5, 0, destination);
            Core.addWeighted(source, 1.5, destination, -0.75, 0, destination);
            Imgcodecs.imwrite("sharpenedCat.jpg", destination);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
Example 4
Project: Java-Data-Science-Made-Easy   File: OpenCVNonMavenExamples.java   Source Code and License Vote up 6 votes
public void sharpenImage() {
        String fileName = "SharpnessExample2.png";
        fileName = "smoothCat.jpg";
        fileName = "blurredText.jpg";
        fileName = "Blurred Text3.jpg";
        try {
//            Not working that well !!!
            Mat source = Imgcodecs.imread(fileName,
                    //                    Imgcodecs.CV_LOAD_IMAGE_COLOR);
                    Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
            Mat destination = new Mat(source.rows(), source.cols(), source.type());
            Imgproc.GaussianBlur(source, destination, new Size(0, 0), 10);
            // The following was used witht he cat
//            Core.addWeighted(source, 1.5, destination, -0.75, 0, destination);
//            Core.addWeighted(source, 2.5, destination, -1.5, 0, destination);
            Core.addWeighted(source, 1.5, destination, -0.75, 0, destination);
            Imgcodecs.imwrite("sharpenedCat.jpg", destination);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
Example 5
Project: AquamarineLake   File: Controller.java   Source Code and License Vote up 6 votes
private void process(Mat f)
  {
  	// grayscale toggle
      if (grayscaleToggle.isSelected()) Imgproc.cvtColor(f, f, Imgproc.COLOR_BGR2GRAY);
      
      // add image to frame
if (thenkToggle.isSelected() && thenkMat != null)
{
	Rect roi = new Rect(f.cols()-thenkMat.cols(), f.rows()-thenkMat.rows(), thenkMat.cols(), thenkMat.rows());
	Mat thenkROI = f.submat(roi);

	Core.addWeighted(thenkROI, 1.0, thenkMat, 1.0, 0.0, thenkROI);
}

  }
 
Example 6
Project: Team9261-2017-2018   File: NewCryptobox.java   Source Code and License Vote up 5 votes
public Mat getRedMask(Mat input){
    Scalar lower1 = new Scalar(0,150,100);
    Scalar upper1 = new Scalar(20,255,255);
    Scalar lower2 = new Scalar(140,100,100);
    Scalar upper2 = new Scalar(179,255,255);
    Core.inRange(input,lower1,upper1,mask1);
    Core.inRange(input,lower2,upper2,mask2);
    Core.addWeighted(mask1,1.0, mask2,1.0, 0.0, mask);
    return mask;
}