当前位置: 首页>>代码示例>>Java>>正文


Java Imgproc.GaussianBlur方法代码示例

本文整理汇总了Java中org.opencv.imgproc.Imgproc.GaussianBlur方法的典型用法代码示例。如果您正苦于以下问题:Java Imgproc.GaussianBlur方法的具体用法?Java Imgproc.GaussianBlur怎么用?Java Imgproc.GaussianBlur使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opencv.imgproc.Imgproc的用法示例。


在下文中一共展示了Imgproc.GaussianBlur方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: skinDetection

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public Mat skinDetection(Mat src) {
        // define the upper and lower boundaries of the HSV pixel
        // intensities to be considered 'skin'
        Scalar lower = new Scalar(0, 48, 80);
        Scalar upper = new Scalar(20, 255, 255);

        // Convert to HSV
        Mat hsvFrame = new Mat(src.rows(), src.cols(), CvType.CV_8U, new Scalar(3));
        Imgproc.cvtColor(src, hsvFrame, Imgproc.COLOR_RGB2HSV, 3);

        // Mask the image for skin colors
        Mat skinMask = new Mat(hsvFrame.rows(), hsvFrame.cols(), CvType.CV_8U, new Scalar(3));
        Core.inRange(hsvFrame, lower, upper, skinMask);
//        currentSkinMask = new Mat(hsvFrame.rows(), hsvFrame.cols(), CvType.CV_8U, new Scalar(3));
//        skinMask.copyTo(currentSkinMask);

        // apply a series of erosions and dilations to the mask
        // using an elliptical kernel
        final Size kernelSize = new Size(11, 11);
        final Point anchor = new Point(-1, -1);
        final int iterations = 2;

        Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, kernelSize);
        Imgproc.erode(skinMask, skinMask, kernel, anchor, iterations);
        Imgproc.dilate(skinMask, skinMask, kernel, anchor, iterations);

        // blur the mask to help remove noise, then apply the
        // mask to the frame
        final Size ksize = new Size(3, 3);

        Mat skin = new Mat(skinMask.rows(), skinMask.cols(), CvType.CV_8U, new Scalar(3));
        Imgproc.GaussianBlur(skinMask, skinMask, ksize, 0);
        Core.bitwise_and(src, src, skin, skinMask);

        return skin;
    }
 
开发者ID:jorenham,项目名称:fingerblox,代码行数:37,代码来源:ImageProcessing.java

示例2: sharpenImage

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
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();
        }
    }
 
开发者ID:PacktPublishing,项目名称:Java-Data-Science-Made-Easy,代码行数:22,代码来源:OpenCVNonMavenExamples.java

示例3: doSobel

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Apply Sobel
 *
 * @param frame the current frame
 * @return an image elaborated with Sobel derivation
 */
private Mat doSobel(Mat frame) {
    // init
    Mat grayImage = new Mat();
    Mat detectedEdges = new Mat();
    int scale = 1;
    int delta = 0;
    int ddepth = CvType.CV_16S;
    Mat grad_x = new Mat();
    Mat grad_y = new Mat();
    Mat abs_grad_x = new Mat();
    Mat abs_grad_y = new Mat();

    // reduce noise with a 3x3 kernel
    Imgproc.GaussianBlur(frame, frame, new Size(3, 3), 0, 0, Core.BORDER_DEFAULT);

    // convert to grayscale
    Imgproc.cvtColor(frame, grayImage, Imgproc.COLOR_BGR2GRAY);

    // Gradient X
    // Imgproc.Sobel(grayImage, grad_x, ddepth, 1, 0, 3, scale,
    // this.threshold.getValue(), Core.BORDER_DEFAULT );
    Imgproc.Sobel(grayImage, grad_x, ddepth, 1, 0);
    Core.convertScaleAbs(grad_x, abs_grad_x);

    // Gradient Y
    // Imgproc.Sobel(grayImage, grad_y, ddepth, 0, 1, 3, scale,
    // this.threshold.getValue(), Core.BORDER_DEFAULT );
    Imgproc.Sobel(grayImage, grad_y, ddepth, 0, 1);
    Core.convertScaleAbs(grad_y, abs_grad_y);

    // Total Gradient (approximate)
    Core.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, detectedEdges);
    // Core.addWeighted(grad_x, 0.5, grad_y, 0.5, 0, detectedEdges);

    return detectedEdges;

}
 
开发者ID:Evegen55,项目名称:main_carauto_board,代码行数:44,代码来源:MagicTabController.java

示例4: blur

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public BufferedImage blur(BufferedImage source, int radius) throws IOException {
    if (!initialized) {
        throw new IOException("OpenCV unavailable");
    }
    Mat sourceMat = getMat(source);
    Mat destination = new Mat(sourceMat.rows(), sourceMat.cols(), sourceMat.type());
    Imgproc.GaussianBlur(sourceMat, destination, new Size(radius, radius), 0);
    return getImage(destination);
}
 
开发者ID:GoldRenard,项目名称:JuniperBotJ,代码行数:10,代码来源:OpenCVService.java

示例5: process

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public void process(Mat input, Mat mask) {
    Imgproc.cvtColor(input,input,Imgproc.COLOR_RGB2HSV_FULL);
    Imgproc.GaussianBlur(input,input,new Size(3,3),0);

    Scalar lower = new Scalar(perfect.val[0] - range.val[0], perfect.val[1] - range.val[1],perfect.val[2] - range.val[2]);
    Scalar upper = new Scalar(perfect.val[0] + range.val[0], perfect.val[1] + range.val[1],perfect.val[2] + range.val[2]);
    Core.inRange(input,lower,upper,mask);
    input.release();
}
 
开发者ID:GTHSRobotics,项目名称:DogeCV,代码行数:11,代码来源:HSVColorFilter.java

示例6: DifferenceOfGaussian

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void DifferenceOfGaussian() {
    Mat grayMat = new Mat();
    Mat blur1 = new Mat();
    Mat blur2 = new Mat();

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

    Imgproc.GaussianBlur(grayMat, blur1, new Size(15, 15), 5);
    Imgproc.GaussianBlur(grayMat, blur2, new Size(21, 21), 5);

    //Subtracting the two blurred images
    Mat DoG = new Mat();
    Core.absdiff(blur1, blur2, DoG);

    //Inverse Binary Thresholding
    Core.multiply(DoG, new Scalar(100), DoG);
    Imgproc.threshold(DoG, DoG, 50, 255, Imgproc.THRESH_BINARY_INV);

    //Converting Mat back to Bitmap
    Utils.matToBitmap(DoG, currentBitmap);
    imageView.setImageBitmap(currentBitmap);
}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:24,代码来源:MainActivity.java

示例7: Saliency

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static Mat Saliency(Mat img) {
	// blur image with a 3x3 or 5x5 Gaussian filter
	Mat gfbgr = new Mat();
	Imgproc.GaussianBlur(img, gfbgr, new Size(3, 3), 3);
	// Perform sRGB to CIE Lab color space conversion
	Mat LabIm = new Mat();
	Imgproc.cvtColor(gfbgr, LabIm, Imgproc.COLOR_BGR2Lab);
	// Compute Lab average values (note that in the paper this average is found from the
	// un-blurred original image, but the results are quite similar)
	List<Mat> lab = new ArrayList<>();
	Core.split(LabIm, lab);
	Mat l = lab.get(0);
	l.convertTo(l, CvType.CV_32F);
	Mat a = lab.get(1);
	a.convertTo(a, CvType.CV_32F);
	Mat b = lab.get(2);
	b.convertTo(b, CvType.CV_32F);
	double lm = Core.mean(l).val[0];
	double am = Core.mean(a).val[0];
	double bm = Core.mean(b).val[0];
	// Finally compute the saliency map
	Mat sm = Mat.zeros(l.rows(), l.cols(), l.type());
	Core.subtract(l, new Scalar(lm), l);
	Core.subtract(a, new Scalar(am), a);
	Core.subtract(b, new Scalar(bm), b);
	Core.add(sm, l.mul(l), sm);
	Core.add(sm, a.mul(a), sm);
	Core.add(sm, b.mul(b), sm);
	return sm;
}
 
开发者ID:IsaacChanghau,项目名称:OptimizedImageEnhance,代码行数:31,代码来源:FeatureWeight.java

示例8: blur

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Softens an image using one of several filters.
 * @param input The image on which to perform the blur.
 * @param type The blurType to perform.
 * @param doubleRadius The radius for the blur.
 * @param output The image in which to store the output.
 */
private void blur(Mat input, BlurType type, double doubleRadius,
	Mat output) {
	int radius = (int)(doubleRadius + 0.5);
	int kernelSize;
	switch(type){
		case BOX:
			kernelSize = 2 * radius + 1;
			Imgproc.blur(input, output, new Size(kernelSize, kernelSize));
			break;
		case GAUSSIAN:
			kernelSize = 6 * radius + 1;
			Imgproc.GaussianBlur(input,output, new Size(kernelSize, kernelSize), radius);
			break;
		case MEDIAN:
			kernelSize = 2 * radius + 1;
			Imgproc.medianBlur(input, output, kernelSize);
			break;
		case BILATERAL:
			Imgproc.bilateralFilter(input, output, -1, radius, radius);
			break;
	}
}
 
开发者ID:trc492,项目名称:Ftc2018RelicRecovery,代码行数:30,代码来源:GripPipeline.java

示例9: blur

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Softens an image using one of several filters.
 * @param input The image on which to perform the blur.
 * @param type The blurType to perform.
 * @param doubleRadius The radius for the blur.
 * @param output The image in which to store the output.
 */
private void blur(Mat input, Blur.Type type, double doubleRadius,
	Mat output) {
	int radius = (int)(doubleRadius + 0.5);
	int kernelSize;
	switch(type){
		case BOX:
			kernelSize = 2 * radius + 1;
			Imgproc.blur(input, output, new Size(kernelSize, kernelSize));
			break;
		case GAUSSIAN:
			kernelSize = 6 * radius + 1;
			Imgproc.GaussianBlur(input,output, new Size(kernelSize, kernelSize), radius);
			break;
		case MEDIAN:
			kernelSize = 2 * radius + 1;
			Imgproc.medianBlur(input, output, kernelSize);
			break;
		case BILATERAL:
			Imgproc.bilateralFilter(input, output, -1, radius, radius);
			break;
	}
}
 
开发者ID:KHS-Robotics,项目名称:DemonVision,代码行数:30,代码来源:DefaultPipeline.java

示例10: leviRedFilter

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void leviRedFilter (Mat input, Mat mask, double threshold){


        Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2Lab);
        Imgproc.GaussianBlur(input,input,new Size(3,3),0);
        Core.split(input, channels);
        Imgproc.threshold(channels.get(1), mask, threshold, 255, Imgproc.THRESH_BINARY);

        for(int i=0;i<channels.size();i++){
            channels.get(i).release();
        }
    }
 
开发者ID:GTHSRobotics,项目名称:DogeCV,代码行数:13,代码来源:LeviColorFilter.java

示例11: leviBlueFilter

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void leviBlueFilter (Mat input, Mat mask){
    List<Mat> channels = new ArrayList<>();

    Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2Lab);
    Imgproc.GaussianBlur(input,input,new Size(3,3),0);
    Core.split(input, channels);
    Imgproc.threshold(channels.get(1), mask, 145, 255, Imgproc.THRESH_BINARY);

    for(int i=0;i<channels.size();i++){
        channels.get(i).release();
    }
}
 
开发者ID:GTHSRobotics,项目名称:DogeCV,代码行数:13,代码来源:LeviColorFilter.java

示例12: setFilter

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private void setFilter() {
    //Apply gaussian blur to remove noise
    Imgproc.GaussianBlur(image, image, new Size(5, 5), 0);

    //Threshold
    Imgproc.adaptiveThreshold(image, image, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 7, 1);
    
    //Invert the image
    Core.bitwise_not(image, image);

    //Dilate
    Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE, new Size(3, 3), new Point(1, 1));
    Imgproc.dilate(image, image, kernel);
}
 
开发者ID:lupino22,项目名称:kronometer,代码行数:15,代码来源:SketchRecognition.java

示例13: main

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static void main(String args[]) {
   System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // Import openCV
   Webcam panel = new Webcam(); // Initialize itself

   // Initialize JPanel
   JFrame frame = new JFrame("Webcam");
   frame.setSize(200, 200);
   frame.setContentPane(panel);
   frame.setVisible(true);

   VideoCapture camera = new VideoCapture(0); // The camera

   // Attempt to set the frame size, but it doesn't really work. Only just makes it bigger
   camera.set(Videoio.CAP_PROP_FRAME_WIDTH, 1900);
   camera.set(Videoio.CAP_PROP_FRAME_HEIGHT, 1000);


   // Special window listener because there are threads that need to be shutdown on a close
   frame.addWindowListener(new WindowAdapter() {
      @Override
      public void windowClosing(WindowEvent e) {
         e.getWindow().dispose();
         camera.release();
         System.exit(0);
      }
   });

   if (camera.isOpened()) {

      // Create SwingWorker to encapsulate the process in a thread
      SwingWorker<Void, Mat> worker = new SwingWorker<Void, Mat>() {
         @Override
         protected Void doInBackground() throws Exception {

            // Put something into thisFrame so it doesn't glitch at the beginning
            Mat thisFrame = new Mat();
            camera.read(thisFrame);
            Imgproc.cvtColor(thisFrame, thisFrame, Imgproc.COLOR_BGR2GRAY); // Convert the diff to gray

            // Set up new Mats for diffing them later, manually set the amount of channels to avoid an openCV error
            Mat pastFrame = new Mat();
            Mat diff = new Mat();


            // isCancelled is set by the SwingWorker
            while (!isCancelled()) {

               thisFrame.copyTo(pastFrame); // What was previously the frame is now the pastFrame
               camera.read(thisFrame); // Get camera image, and set it to currentImage
               Imgproc.cvtColor(thisFrame, thisFrame, Imgproc.COLOR_BGR2GRAY); // Convert the diff to gray

               if (!thisFrame.empty()) {

                  // Set the frame size to have a nice border around the image
                  frame.setSize(thisFrame.width() + 40, thisFrame.height() + 60);


                  Core.absdiff(thisFrame, pastFrame, diff); // Diff the frames
                  Imgproc.GaussianBlur(diff, diff, new Size(7, 7), 7); // Despeckle
                  Imgproc.threshold(diff, diff, 5, 255, 1); // Threshhold the gray

                  image = matrixToBuffer(getFace(thisFrame, diff)); // Update the display image
                  panel.repaint(); // Refresh the panel
               } else {
                  System.err.println("Error: no frame captured");
               }
               //Thread.sleep(70); // Set refresh rate, as well as prevent the code from tripping over itself
            }
            return null;
         }
      };
      worker.execute();
   }
   return;
}
 
开发者ID:grantslatton,项目名称:GarfieldLanguage,代码行数:76,代码来源:Webcam.java

示例14: process

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public void process(Mat input, Mat mask) {
    channels = new ArrayList<>();

    switch(color){
        case RED:
            if(threshold == -1){
                threshold = 164;
            }

            Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2Lab);
            Imgproc.GaussianBlur(input,input,new Size(3,3),0);
            Core.split(input, channels);
            Imgproc.threshold(channels.get(1), mask, threshold, 255, Imgproc.THRESH_BINARY);
            break;
        case BLUE:
            if(threshold == -1){
                threshold = 145;
            }

            Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2YUV);
            Imgproc.GaussianBlur(input,input,new Size(3,3),0);
            Core.split(input, channels);
            Imgproc.threshold(channels.get(1), mask, threshold, 255, Imgproc.THRESH_BINARY);
            break;
        case YELLOW:
            if(threshold == -1){
                threshold = 95;
            }

            Imgproc.cvtColor(input, input, Imgproc.COLOR_RGB2YUV);
            Imgproc.GaussianBlur(input,input,new Size(3,3),0);
            Core.split(input, channels);
            Imgproc.threshold(channels.get(1), mask, threshold, 255, Imgproc.THRESH_BINARY_INV);
            break;
    }

    for(int i=0;i<channels.size();i++){
        channels.get(i).release();
    }

    input.release();

}
 
开发者ID:GTHSRobotics,项目名称:DogeCV,代码行数:45,代码来源:LeviColorFilter.java

示例15: processarImagem

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public Mat processarImagem(Mat imagemOriginal) {
    Mat imagemTratada = new Mat(imagemOriginal.rows(), imagemOriginal.cols(), imagemOriginal.type());
    Imgproc.GaussianBlur(imagemOriginal, imagemTratada, new Size(3, 3), 2);
    return imagemTratada;
}
 
开发者ID:nbfontana,项目名称:pdi,代码行数:7,代码来源:AlgoritmoGaussiana.java


注:本文中的org.opencv.imgproc.Imgproc.GaussianBlur方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。