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


Java Imgproc.blur方法代码示例

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


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

示例1: doCanny

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Apply Canny
 *
 * @param frame the current frame
 * @return an image elaborated with Canny
 */
private Mat doCanny(Mat frame) {
    // init
    Mat grayImage = new Mat();
    Mat detectedEdges = new Mat();

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

    // reduce noise with a 3x3 kernel
    Imgproc.blur(grayImage, detectedEdges, new Size(3, 3));

    // canny detector, with ratio of lower:upper threshold of 3:1
    Imgproc.Canny(detectedEdges, detectedEdges, threshold.getValue(), threshold.getValue() * 3);

    // using Canny's output as a mask, display the result
    Mat dest = new Mat();
    frame.copyTo(dest, detectedEdges);

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

示例2: smoothImage

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public void smoothImage() {
    // Smoothing, also called blurring, will make the edges soother.
    Mat source = Imgcodecs.imread("cat.jpg");
    Mat destination = source.clone();
    for (int i = 0; i < 25; i++) {
        Mat sourceImage = destination.clone();
        Imgproc.blur(sourceImage, destination, new Size(3.0, 3.0));
    }
    Imgcodecs.imwrite("smoothCat.jpg", destination);
}
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:11,代码来源:OpenCVNonMavenExamples.java

示例3: 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:chopshop-166,项目名称:frc-2017,代码行数:34,代码来源:Vision.java

示例4: 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

示例5: preprocess

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private static boolean preprocess(Mat im) {
    // check time
    if (!checkTime()) {
        return false;
    }

    // resize to the standard size
    recoverRatio = 1.0 / Util.resize(im);

    Imgproc.cvtColor(im, im, Imgproc.COLOR_BGR2YCrCb);
    Imgproc.blur(im, im, new Size(Config.IM_BLUR_SIZE, Config.IM_BLUR_SIZE));

    if (!Sampler.sampleCompleted()) {
        sample(im);
        return false;
    }
    return true;
}
 
开发者ID:hgs1217,项目名称:Paper-Melody,代码行数:19,代码来源:Tap.java

示例6: 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

示例7: FloodFillDemo

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public FloodFillDemo() {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    frame1 = Imgcodecs.imread("frame1.png");
    frame2 = Imgcodecs.imread("frame2.png");

    grayscaleMat = frame1.clone();
    originalMat = frame1.clone();
    
    // apply gaussian filter on both the frames to cancel out noise
    Imgproc.blur(frame1, frame1, new Size(5.0, 5.0));
    Imgproc.blur(frame2, frame2, new Size(5.0, 5.0));
    
    System.out.println("Height " + frame1.height());
    System.out.println("Width " + frame1.width());
    calculateDifference(frame1, frame2, grayscaleMat);
    Imgcodecs.imwrite("difference.png", grayscaleMat);
    
    // since we use the result from one process in another
    // at the end of the last process (here process(2))
    // we will have the final output (including all three channels)
    // written in output2.png
    process(0);
    process(1);
    process(2);
}
 
开发者ID:kmhasan-class,项目名称:fall2017ip,代码行数:26,代码来源:FloodFillDemo.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:cyborgs3335,项目名称:STEAMworks,代码行数:34,代码来源:GripPipelineWithBlur.java

示例9: getOpenCvLines

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
public static List<Line> getOpenCvLines(Mat original, int scale, double minLength) {
    Mat raw = new Mat();
    Imgproc.resize(original.clone(), raw, new Size((int) (original.size().width/scale), (int) (original.size().height/scale)));
    if(raw.channels() > 1) {
        Imgproc.cvtColor(raw, raw, Imgproc.COLOR_RGB2GRAY);
    }
    Imgproc.equalizeHist(raw, raw);
    Imgproc.blur(raw, raw, new Size(3,3));
    //Line Segment Detection 2
    Mat linesM1 = new Mat();
    //LineSegmentDetector detector = Imgproc.createLineSegmentDetector(Imgproc.LSD_REFINE_ADV, 0.6, 0.3, 2.6, 22.5, 0, 0.3,256);
    //LineSegmentDetector detector = Imgproc.createLineSegmentDetector(Imgproc.LSD_REFINE_STD, 0.5, 0.4,2.0, 19.5, 0, 0.6, 32);
    //Reference for final glyph detection

    detector.detect(raw, linesM1);
    ArrayList<Line> lines = new ArrayList<Line>();
    for (int x = 0; x < linesM1.rows(); x++)  {
        double[] vec = linesM1.get(x, 0);
        Point start = new Point(vec[0],vec[1]);
        Point end = new Point(vec[2], vec[3]);
        Line line = new Line(start, end);
        line = new Line(new Point((int)line.x1*scale, (int) line.y1*scale), new Point((int)line.x2*scale, (int)line.y2*scale));
        if(line.length() > minLength) lines.add(line);
    }

    raw.release();
    linesM1.release();

    return lines;
}
 
开发者ID:GTHSRobotics,项目名称:DogeCV,代码行数:31,代码来源:Lines.java

示例10: onCameraFrame

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
    Mat input = inputFrame.gray();
    Mat circles = new Mat();
    Imgproc.blur(input, input, new Size(7, 7), new Point(2, 2));
    Imgproc.HoughCircles(input, circles, Imgproc.CV_HOUGH_GRADIENT, 2, 100, 100, 90, 0, 1000);

    Log.i(TAG, String.valueOf("size: " + circles.cols()) + ", " + String.valueOf(circles.rows()));

    if (circles.cols() > 0) {
        for (int x=0; x < Math.min(circles.cols(), 5); x++ ) {
            double circleVec[] = circles.get(0, x);

            if (circleVec == null) {
                break;
            }

            Point center = new Point((int) circleVec[0], (int) circleVec[1]);
            int radius = (int) circleVec[2];

            Imgproc.circle(input, center, 3, new Scalar(255, 255, 255), 5);
            Imgproc.circle(input, center, radius, new Scalar(255, 255, 255), 2);
        }
    }

    circles.release();
    input.release();
    return inputFrame.rgba();
}
 
开发者ID:ahmetozlu,项目名称:real_time_circle_detection_android,代码行数:30,代码来源:MainActivity.java

示例11: doBackgroundRemoval

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
/**
 * Perform the operations needed for removing a uniform background
 *
 * @param frame the current frame
 * @return an image with only foreground objects
 */
private Mat doBackgroundRemoval(Mat frame) {
    // init
    Mat hsvImg = new Mat();
    List<Mat> hsvPlanes = new ArrayList<>();
    Mat thresholdImg = new Mat();

    int thresh_type = Imgproc.THRESH_BINARY_INV;
    if (inverse.isSelected())
        thresh_type = Imgproc.THRESH_BINARY;

    // threshold the image with the average hue value
    hsvImg.create(frame.size(), CvType.CV_8U);
    Imgproc.cvtColor(frame, hsvImg, Imgproc.COLOR_BGR2HSV);
    Core.split(hsvImg, hsvPlanes);

    // get the average hue value of the image
    double threshValue = getHistAverage(hsvImg, hsvPlanes.get(0));

    Imgproc.threshold(hsvPlanes.get(0), thresholdImg, threshValue, 179.0, thresh_type);

    Imgproc.blur(thresholdImg, thresholdImg, new Size(5, 5));

    // dilate to fill gaps, erode to smooth edges
    Imgproc.dilate(thresholdImg, thresholdImg, new Mat(), new Point(-1, -1), 1);
    Imgproc.erode(thresholdImg, thresholdImg, new Mat(), new Point(-1, -1), 3);

    Imgproc.threshold(thresholdImg, thresholdImg, threshValue, 179.0, Imgproc.THRESH_BINARY);

    // create the new image
    Mat foreground = new Mat(frame.size(), CvType.CV_8UC3, new Scalar(255, 255, 255));
    frame.copyTo(foreground, thresholdImg);

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

示例12: boxfilter

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
private static Mat boxfilter(Mat I, int r) {
	Mat result = new Mat();
	Imgproc.blur(I, result, new Size(r, r));
	return result;
}
 
开发者ID:IsaacChanghau,项目名称:OptimizedImageEnhance,代码行数:6,代码来源:Filters.java

示例13: onActivityResult

import org.opencv.imgproc.Imgproc; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
    //Put it there, just in case:)
    super.onActivityResult(requestCode, resultCode, imageReturnedIntent);

    switch(requestCode) {
        case SELECT_PHOTO:
            if(resultCode == RESULT_OK && read_external_storage_granted){
                try {
                    final Uri imageUri = imageReturnedIntent.getData();
                    final InputStream imageStream = getContentResolver().openInputStream(imageUri);
                    final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
                    src = new Mat(selectedImage.getHeight(), selectedImage.getWidth(), CvType.CV_8UC4);
                    Utils.bitmapToMat(selectedImage, src);
                    src_gray = new Mat(selectedImage.getHeight(), selectedImage.getWidth(), CvType.CV_8UC1);
                    switch (ACTION_MODE) {
                        case HomeActivity.GAUSSIAN_BLUR:
                            Imgproc.GaussianBlur(src, src, new Size(9, 9), 0);
                            break;
                        case HomeActivity.MEAN_BLUR:
                            Imgproc.blur(src, src, new Size(9, 9));
                            break;
                        case HomeActivity.MEDIAN_BLUR:
                            Imgproc.medianBlur(src, src, 9);
                            break;
                        case HomeActivity.SHARPEN:
                            Mat kernel = new Mat(3, 3, CvType.CV_16SC1);
                            //int[] values = {0, -1, 0, -1, 5, -1, 0, -1, 0};
                            Log.d("imageType", CvType.typeToString(src.type()) + "");
                            kernel.put(0, 0, 0, -1, 0, -1, 5, -1, 0, -1, 0);
                            Imgproc.filter2D(src, src, src_gray.depth(), kernel);
                            break;
                        case HomeActivity.DILATE:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY);
                            Mat kernelDilate = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3, 3));
                            Imgproc.dilate(src_gray, src_gray, kernelDilate);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                        case HomeActivity.ERODE:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY);
                            Mat kernelErode = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(5, 5));
                            Imgproc.erode(src_gray, src_gray, kernelErode);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                        case HomeActivity.THRESHOLD:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.threshold(src_gray, src_gray, 100, 255, Imgproc.THRESH_BINARY);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                        case HomeActivity.ADAPTIVE_THRESHOLD:
                            Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_BGR2GRAY);
                            Imgproc.adaptiveThreshold(src_gray, src_gray, 255, Imgproc.ADAPTIVE_THRESH_GAUSSIAN_C, Imgproc.THRESH_BINARY, 3, 0);
                            Imgproc.cvtColor(src_gray, src, Imgproc.COLOR_GRAY2RGBA, 4);
                            break;
                    }
                    Bitmap processedImage = Bitmap.createBitmap(src.cols(), src.rows(), Bitmap.Config.ARGB_8888);
                    Log.i("imageType", CvType.typeToString(src.type()) + "");
                    Utils.matToBitmap(src, processedImage);
                    ivImage.setImageBitmap(selectedImage);
                    ivImageProcessed.setImageBitmap(processedImage);
                    Log.i("process", "process done");
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }
            }
            break;
    }
}
 
开发者ID:johnhany,项目名称:MOAAP,代码行数:71,代码来源:MainActivity.java


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