Java Code Examples for org.opencv.imgproc.Imgproc#blur()
The following examples show how to use
org.opencv.imgproc.Imgproc#blur() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From MOAAP with MIT License | 6 votes |
@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; } }
Example 2
Source File: GripPipeline.java From FtcSamples with MIT License | 6 votes |
/** * 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; } }
Example 3
Source File: Finder.java From SikuliNG with MIT License | 6 votes |
public static Mat detectEdges(Mat mSource) { Mat mSourceGray = Element.getNewMat(); Mat mDetectedEdges = Element.getNewMat(); int edgeThresh = 1; int lowThreshold = 100; int ratio = 3; int kernelSize = 5; int blurFilterSize = 3; if (mSource.channels() == 1) { mSourceGray = mSource; } else { Imgproc.cvtColor(mSource, mSourceGray, toGray); } Imgproc.blur(mSourceGray, mDetectedEdges, new Size(blurFilterSize, blurFilterSize)); Imgproc.Canny(mDetectedEdges, mDetectedEdges, lowThreshold, lowThreshold * ratio, kernelSize, false); return mDetectedEdges; }
Example 4
Source File: HistogramEqualization.java From opencv-fun with GNU Affero General Public License v3.0 | 6 votes |
public static void main (String[] args) { CVLoader.load(); // load the image Mat img = Highgui.imread("data/topdown-9.png"); Mat equ = new Mat(); img.copyTo(equ); Imgproc.blur(equ, equ, new Size(3, 3)); Imgproc.cvtColor(equ, equ, Imgproc.COLOR_BGR2YCrCb); List<Mat> channels = new ArrayList<Mat>(); Core.split(equ, channels); Imgproc.equalizeHist(channels.get(0), channels.get(0)); Core.merge(channels, equ); Imgproc.cvtColor(equ, equ, Imgproc.COLOR_YCrCb2BGR); Mat gray = new Mat(); Imgproc.cvtColor(equ, gray, Imgproc.COLOR_BGR2GRAY); Mat grayOrig = new Mat(); Imgproc.cvtColor(img, grayOrig, Imgproc.COLOR_BGR2GRAY); ImgWindow.newWindow(img); ImgWindow.newWindow(equ); ImgWindow.newWindow(gray); ImgWindow.newWindow(grayOrig); }
Example 5
Source File: OpenCVNonMavenExamples.java From Java-for-Data-Science with MIT License | 5 votes |
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); }
Example 6
Source File: MainActivity.java From real_time_circle_detection_android with MIT License | 5 votes |
@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(); }
Example 7
Source File: Lines.java From DogeCV with GNU General Public License v3.0 | 5 votes |
/** * Modern OpenCV line segment detection - far better than Canny, but must be carefully adjusted. * @param original The original image to be scanned, as an RGB image * @param scale The factor by which the image is to be downscaled * @param minLength The minimum line segment length to be returned * @return A List of Lines found */ 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(); 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; }
Example 8
Source File: UnsharpenMaskProcessor.java From Camdroid with Apache License 2.0 | 5 votes |
protected void execute() { out = this.rgb(); Imgproc.blur(out, this.mask, new Size(sigma_x, sigma_x)); Core.addWeighted(out, (double) alpha / 10, this.mask, ((double) beta - 10) / 10, 0, out); }
Example 9
Source File: BackgroundSubtractor.java From opencv-fun with GNU Affero General Public License v3.0 | 5 votes |
public Mat createMask(Mat camera) { // copy as we are going to destruct those images maybe Mat camBlur= camera.clone(); Mat backgroundBlur = calib.getBackgroundImage().clone(); // remove noise Imgproc.blur(backgroundBlur, backgroundBlur, new Size(calib.getBlurSize(), calib.getBlurSize())); Imgproc.blur(camBlur, camBlur, new Size(calib.getBlurSize(), calib.getBlurSize())); // take abs diff and create binary image in all 3 channels Mat diff = new Mat(); Core.absdiff(backgroundBlur, camBlur, diff); Imgproc.threshold(diff, diff, calib.getSubtractionThreshold(), 255, Imgproc.THRESH_BINARY); // extract color channels and merge them to single bitmask Mat r = ColorSpace.getChannel(diff, 2); Mat g = ColorSpace.getChannel(diff, 1); Mat b = ColorSpace.getChannel(diff, 0); Mat mask = r.clone(); Core.add(mask, g, mask); Core.add(mask, b, mask); // dilate to remove some black gaps within balls Imgproc.dilate(mask, mask, Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, new Size(calib.getMorphSize(), calib.getMorphSize()))); return mask; }
Example 10
Source File: HoughLines.java From opencv-fun with GNU Affero General Public License v3.0 | 5 votes |
public static void main (String[] args) { CVLoader.load(); // load the image Mat img = Highgui.imread("data/topdown-6.jpg"); // generate gray scale and blur Mat gray = new Mat(); Imgproc.cvtColor(img, gray, Imgproc.COLOR_BGR2GRAY); Imgproc.blur(gray, gray, new Size(3, 3)); // detect the edges Mat edges = new Mat(); int lowThreshold = 50; int ratio = 3; Imgproc.Canny(gray, edges, lowThreshold, lowThreshold * ratio); Mat lines = new Mat(); Imgproc.HoughLinesP(edges, lines, 1, Math.PI / 180, 50, 50, 10); for(int i = 0; i < lines.cols(); i++) { double[] val = lines.get(0, i); Core.line(img, new Point(val[0], val[1]), new Point(val[2], val[3]), new Scalar(0, 0, 255), 2); } ImgWindow.newWindow(edges); ImgWindow.newWindow(gray); ImgWindow.newWindow(img); }
Example 11
Source File: Filters.java From OptimizedImageEnhance with MIT License | 4 votes |
private static Mat boxfilter(Mat I, int r) { Mat result = new Mat(); Imgproc.blur(I, result, new Size(r, r)); return result; }
Example 12
Source File: Filters.java From ImageEnhanceViaFusion with MIT License | 4 votes |
private static Mat boxfilter(Mat I, int r) { Mat result = new Mat(); Imgproc.blur(I, result, new Size(r, r)); return result; }
Example 13
Source File: CannyEdgesProcessor.java From Camdroid with Apache License 2.0 | 4 votes |
protected void execute() { out = gray(); Imgproc.blur(out, out, new Size(3, 3)); Imgproc.Canny(out, out, min, max); }