List of usage examples for org.opencv.imgproc Imgproc getStructuringElement
public static Mat getStructuringElement(int shape, Size ksize, Point anchor)
From source file:Clases.Segmentador.java
public Mat eriosionarImg(Mat umbralizada) { Mat dste = umbralizada.clone();//from w ww. ja v a 2 s. c o m int erosion_size = 5; Size s = new Size(2 * erosion_size + 1, 2 * erosion_size + 1); Point p = new Point(erosion_size, erosion_size); Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, s, p); Imgproc.erode(umbralizada, dste, element); return dste; }
From source file:Clases.Segmentador.java
public Mat dilatarImg(Mat umbralizada) { Mat dstd = umbralizada.clone();/*from ww w . ja va 2s . co m*/ int dilatacion_size = 5; Size sd = new Size(2 * dilatacion_size + 1, 2 * dilatacion_size + 1); Point pd = new Point(dilatacion_size, dilatacion_size); Mat elementd = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, sd, pd); Imgproc.dilate(umbralizada, dstd, elementd); return dstd; }
From source file:com.compta.firstak.notedefrais.MainActivity.java
public void Opencv(String imageName) { bitmap = BitmapFactory.decodeFile(imageName); Mat imageMat = new Mat(); org.opencv.android.Utils.bitmapToMat(bitmap, imageMat); Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_BGR2GRAY); // 1) Apply gaussian blur to remove noise Imgproc.GaussianBlur(imageMat, imageMat, new Size(9, 9), 0); // 2) AdaptiveThreshold -> classify as either black or white Imgproc.adaptiveThreshold(imageMat, imageMat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 5, 2);/*from w w w .j a v a2s . c om*/ // 3) Invert the image -> so most of the image is black Core.bitwise_not(imageMat, imageMat); // 4) Dilate -> fill the image using the MORPH_DILATE Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE, new Size(3, 3), new Point(1, 1)); Imgproc.dilate(imageMat, imageMat, kernel); org.opencv.android.Utils.matToBitmap(imageMat, bitmap); mImageViewer.setImageBitmap(bitmap); ByteArrayOutputStream stream1 = new ByteArrayOutputStream(); bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream1); byteArray = stream1.toByteArray(); }
From source file:org.lasarobotics.vision.image.Filter.java
License:Open Source License
/** * Erode the image using morphological transformations * * @param img Image matrix/*from w w w. j a v a2 s. c om*/ * @param amount Amount to erode = 0 */ public static void erode(Mat img, int amount) { Mat kernel = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(2 * amount + 1, 2 * amount + 1), new Point(amount, amount)); Imgproc.erode(img, img, kernel); }
From source file:org.lasarobotics.vision.image.Filter.java
License:Open Source License
/** * Dilate the image using morphological transformations * * @param img Image matrix/*from www . j a v a 2s . co m*/ * @param amount Amount to dilate = 0 */ public static void dilate(Mat img, int amount) { Mat kernel = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(2 * amount + 1, 2 * amount + 1), new Point(amount, amount)); Imgproc.dilate(img, img, kernel); }
From source file:src.model.filters.DotsFilter.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("**______________DOTS_______________**"); try {//w w w .j av a 2 s .co m String imgInput = request.getParameter("name").toString(); String savePath = savePath(request); //____________________________________ int elementSize = 2; int bsize = 10; Mat source = Imgcodecs.imread(savePath); Mat dst = zeros(source.size(), CV_8UC3); Mat cir = zeros(source.size(), CV_8UC1); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Mat element = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(elementSize * 3 + 1, elementSize * 3 + 1), new Point(elementSize, elementSize)); for (int i = 0; i < source.rows(); i += bsize) { for (int j = 0; j < source.cols(); j += bsize) { circle(cir, new Point(j + bsize / (double) 2, i + bsize / (double) 2), bsize / 2 - 1, new Scalar(255, 255, 255), -1, -1, Core.LINE_AA); } } Imgproc.morphologyEx(source, dst, Imgproc.MORPH_CLOSE, element); Mat cir_32f = new Mat(source.rows(), source.cols(), CV_32F); cir.convertTo(cir_32f, CV_32F); normalize(cir_32f, cir_32f, 0, 1, NORM_MINMAX); Mat dst_32f = new Mat(source.rows(), source.cols(), CV_32F); dst.convertTo(dst_32f, CV_32F); Vector<Mat> channels = new Vector(); split(dst_32f, channels); System.out.println(channels.size()); for (int i = 0; i < channels.size(); ++i) { channels.set(i, channels.get(i).mul(cir_32f)); } merge(channels, dst_32f); dst_32f.convertTo(dst, CV_8U); // Core.gemm(source, source, bsize, source, bsize, dst); // Core.gemm(cir, destination, 1, new Mat(), 0,dst , 0); // Imgcodecs.imwrite("images\\outddput.jpg", dst); String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_DOTS_temp.jpg"; imgInput = request.getParameter("name").toString(); String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_DOTS_temp.jpg"; Imgcodecs.imwrite(output, dst); //____________________________________ System.out.println("output: " + output); System.out.println("imgOutput: " + imgOutput); publishImg(response, imgOutput); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }
From source file:src.model.filters.MorphFilter.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("**______________MORPH_______________**"); try {/*from ww w . j ava2 s . c o m*/ String imgInput = request.getParameter("name").toString(); String savePath = savePath(request); //____________________________________ int elementSize = 9; Mat source = Imgcodecs.imread(savePath); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Mat element = Imgproc.getStructuringElement(Imgproc.CV_SHAPE_RECT, new Size(elementSize * 2 + 1, elementSize * 2 + 1), new Point(elementSize, elementSize)); Imgproc.morphologyEx(source, destination, Imgproc.MORPH_GRADIENT, element); String output = savePath.substring(0, savePath.lastIndexOf(".")) + "_MORPH_temp.jpg"; imgInput = request.getParameter("name").toString(); String imgOutput = imgInput.substring(0, imgInput.lastIndexOf(".")) + "_MORPH_temp.jpg"; Imgcodecs.imwrite(output, destination); //____________________________________ System.out.println("output: " + output); System.out.println("imgOutput: " + imgOutput); publishImg(response, imgOutput); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); } }