List of usage examples for org.opencv.imgproc Imgproc blur
public static void blur(Mat src, Mat dst, Size ksize)
From source file:Questao2.java
void media() { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); String url = escolherUrl();/*ww w. j a v a 2s. c o m*/ /** * Transforma imagem em matriz para facilitar manipulacao */ Mat img = Imgcodecs.imread(url); /** * Cria matriz de destino */ Mat dst = new Mat(); /** * Aplicacao do filtro da media * blur(matriz original, matriz destino, tamanho da mascara) */ System.out.println("Escolha as dimenses da mscara: "); System.out.print("X: "); int mx = in.nextInt(); System.out.print("Y: "); int my = in.nextInt(); Imgproc.blur(img, dst, new Size(mx, my)); /** * Salva o resultado em media.jpg */ Imgcodecs.imwrite("media.jpg", dst); showResult("media.jpg"); }
From source file:android.google.com.basiccamera.imageprocessing.CannyEdgeDetector.java
License:BSD License
protected void runTask() { Log.i(TAG, "Starting heavy image processing task"); while (running) { Long begin, end;/*from w w w . ja v a2 s . co m*/ //begin = System.currentTimeMillis(); // requests picture and blocks till it receives one mTaskManager.requestPreviewFrame(); //end = System.currentTimeMillis(); //Log.i(TAG, "Process took " + String.valueOf(end - begin) + " ms"); byte[] image = getImage(); if (image == null) { Log.w(TAG, "Received null as picture"); } // do Canny edge detection Mat img = new Mat(); Bitmap bmp = BitmapFactory.decodeByteArray(image, 0, image.length); Utils.bitmapToMat(bmp, img); Imgproc.cvtColor(img, img, Imgproc.COLOR_RGB2GRAY); Imgproc.blur(img, img, new Size(3, 3)); Imgproc.Canny(img, img, 20, 100); Utils.matToBitmap(img, bmp); mTaskManager.drawResult(bmp); } return; }
From source file:com.joowon.returnA.classifier.cv.PdfPageDivider.java
License:Open Source License
public PdfPageDivider divide() { // 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); lines = new Mat(); Imgproc.HoughLinesP(edges, lines, 10, Math.PI / 180, 50, 50, 10); return this; }
From source file:contador_de_moedas.Segmentacao.java
/** * Apply Canny/*from w w w. j a v a 2s . c o m*/ * * @param img the current frame * @return an image elaborated with Canny */ private Mat doCanny(Mat img) { // inicia Mat grayImage = new Mat(); Mat detectedEdges = new Mat(); // Reduzir o rudo com um kernel 3x3 Imgproc.blur(grayImage, detectedEdges, new Size(3, 3)); //Detector canny, com relao de menor: limite de superior de 3: 1 Imgproc.Canny(detectedEdges, detectedEdges, this.threshold.getValue(), this.threshold.getValue() * 3); //Usando Canny e exibindo o resultadosada como uma mscara. Mat dest = new Mat(); img.copyTo(dest, detectedEdges); return dest; }
From source file:ctPrincipal.Filtros.java
private String media(int mx, int my) { Mat img = Imgcodecs.imread(imgS);//from www .j av a2s . c o m Imgproc.blur(img, output, new Size(mx, my)); Imgcodecs.imwrite("OutputImg/media.jpg", output); return "OutputImg/media.jpg"; }
From source file:cubesolversimulator.VisualInputForm.java
private void blurOriginal() { Imgproc.blur(orig, blured, new Size(18, 18)); Highgui.imwrite("blured.jpg", blured); img1 = new JLabel(""); img1.setSize(jPanel4.getSize());/*from www .j a v a 2s. c o m*/ image1 = new ImageIcon(new ImageIcon("D:\\Project_work\\CubeSolverSimulator\\blured.jpg").getImage() .getScaledInstance(img1.getWidth(), img1.getHeight(), Image.SCALE_FAST)); img1.setIcon(image1); img1.repaint(); jPanel4.add(img1); jPanel4.repaint(); }
From source file:cv.recon.util.CannyDetector.java
License:Open Source License
/** * Apply Canny detector to Mat./* www .j a v a 2 s . com*/ * @param src Input Mat * @param dst Output Mat */ public void detect(Mat src, Mat dst) { Mat src_gray = new Mat(); Mat detected_edges = new Mat(); Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_RGB2GRAY); Imgproc.blur(src_gray, detected_edges, new Size(3, 3)); Imgproc.Canny(detected_edges, detected_edges, lowThreshold, lowThreshold * ratio, kernel_size, true); dst.setTo(new Scalar(0)); src.copyTo(dst, detected_edges); }
From source file:cx.uni.jk.mms.iaip.brush.BrushModel.java
License:Open Source License
private void updateAlphaMat() { this.alphaMat = Mat.zeros(this.size, this.size, MatModel.MAT_TYPE); switch (this.shape) { case SQUARE://w ww .jav a2 s . co m Core.add(this.alphaMat, new Scalar(1.0f), this.alphaMat); break; case CIRCLE: Core.circle(this.alphaMat, new Point((this.size - 1) * 0.5d, (this.size - 1) * 0.5d), (this.size - 1) / 2, new Scalar(1.0f), -1); break; case SOFT_CIRCLE: { Mat temp = this.alphaMat.clone(); Core.circle(temp, new Point((this.size - 1) * 0.5d, (this.size - 1) * 0.5d), (this.size - 1) / 4, new Scalar(1.0f), -1); Imgproc.blur(temp, this.alphaMat, new Size(this.size * 0.5d, this.size * 0.5d)); } break; default: /** this must not happen, die */ throw new RuntimeException("unexpected BrushModel.Shape = " + this.shape); } }
From source file:depthDataFromStereoCamsOpenCV.ProcessImages.java
/** * Applies Canny edge detection algorithm * @param Mat image//w w w . j a v a2s .com * @return Mat */ public static Mat applyCannyEdgeDetectorOpenCV_Mat(Mat image) { //TODO //all these parameters have to be investigated Mat result = image.clone(); int lowThreshold = 40; int ratio = 120; int kernel_size = 3; Imgproc.blur(result, result, new Size(2, 2)); Imgproc.Canny(result, result, lowThreshold, ratio, kernel_size, true); //Imgproc.threshold(result,result,64, 254,Imgproc.THRESH_BINARY_INV); return result; }
From source file:detectiontest.ParticleDetector.java
/** * Particle detection algorithm./* w w w .j a va 2 s .com*/ * * @param image an image where we want to detect * @return list of detected particles */ public static List<Particle> detect(Mat image) { // blur the image to denoise Imgproc.blur(image, image, new Size(3, 3)); // thresholds the image Mat thresholded = new Mat(); Imgproc.threshold(image, thresholded, THRESHOLD, MAX, Imgproc.THRESH_TOZERO_INV); // detect contours List<MatOfPoint> contours = new ArrayList<>(); Imgproc.findContours(thresholded, contours, new Mat(), Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE, ORIGIN); // create particle from each contour List<Particle> particles = new ArrayList<>(); for (MatOfPoint contour : contours) { particles.add(new Particle(contour)); } return particles; }