List of usage examples for org.opencv.core Mat Mat
public Mat(Mat m, Range rowRange, Range colRange)
From source file:OCV_DistanceTransform.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // srcdst//from w w w . j a v a 2 s .c o m int imw = ip.getWidth(); int imh = ip.getHeight(); float[] srcdst_floats = (float[]) ip.getPixels(); // mat Mat src_mat_32f = new Mat(imh, imw, CvType.CV_32FC1); Mat src_mat_8u = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat_32f = new Mat(imh, imw, CvType.CV_32FC1); // run src_mat_32f.put(0, 0, srcdst_floats); src_mat_32f.convertTo(src_mat_8u, CvType.CV_8UC1); Imgproc.distanceTransform(src_mat_8u, dst_mat_32f, INT_DISTANCETYPE[indDistType], INT_DISTANCETRANSFORMMASKS[indMskSize]); dst_mat_32f.get(0, 0, srcdst_floats); }
From source file:OCV_Watershed.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // src (RGB)//from ww w . j a va 2 s. c om int[] arr_src_rgb = (int[]) imp_src.getChannelProcessor().getPixels(); int imw_src = imp_src.getWidth(); int imh_src = imp_src.getHeight(); Mat mat_src_rgb = new Mat(imh_src, imw_src, CvType.CV_8UC3); // map (32bit) float[] arr_map_32f = (float[]) imp_map.getChannelProcessor().getPixels(); int imw_map = imp_map.getWidth(); int imh_map = imp_map.getHeight(); Mat mat_map_32f = new Mat(imh_map, imw_map, CvType.CV_32FC1); Mat mat_map_32s = new Mat(imh_map, imw_map, CvType.CV_32SC1); // run OCV__LoadLibrary.intarray2mat(arr_src_rgb, mat_src_rgb, imw_src, imh_src); mat_map_32f.put(0, 0, arr_map_32f); mat_map_32f.convertTo(mat_map_32s, CvType.CV_32SC1); Imgproc.watershed(mat_src_rgb, mat_map_32s); mat_map_32s.convertTo(mat_map_32f, CvType.CV_32FC1); mat_map_32f.get(0, 0, arr_map_32f); }
From source file:MainDilation.java
public static void main(String[] args) { try {// ww w .j a va 2s. c o m //int erosion_size = 5; int dilation_size = 5; System.loadLibrary(Core.NATIVE_LIBRARY_NAME); Mat source = Highgui.imread("D://teste.png", Highgui.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows(), source.cols(), source.type()); destination = source; Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(2 * dilation_size + 1, 2 * dilation_size + 1)); Imgproc.dilate(source, destination, element); Highgui.imwrite("D://Dilation.jpg", destination); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } }
From source file:MainTextWatermark.java
public static void main(String[] args) { try {// w w w. j a va2 s .c om System.loadLibrary(Core.NATIVE_LIBRARY_NAME); Mat source = Highgui.imread("D://teste.png", Highgui.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows(), source.cols(), source.type()); Core.putText(source, "Tutorialspoint.com by DAC", new Point(source.rows() / 2, (source.cols() / 15 * 11)), //Posio do texto na tela Core.FONT_HERSHEY_PLAIN, new Double(1.1), new Scalar(150)); Highgui.imwrite("D://Watermarked.jpg", source); } catch (Exception e) { System.out.println("Exception:" + e.getMessage()); } }
From source file:OCV_GaussianBlur.java
License:Open Source License
@Override public void run(ImageProcessor ip) { if (ip.getBitDepth() == 8) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat//from w w w.ja v a 2 s .c o m Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.GaussianBlur(src_mat, dst_mat, ksize, sigma_x, sigma_y, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_bytes); } else if (ip.getBitDepth() == 16) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); short[] srcdst_shorts = (short[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_16S); Mat dst_mat = new Mat(imh, imw, CvType.CV_16S); // run src_mat.put(0, 0, srcdst_shorts); Imgproc.GaussianBlur(src_mat, dst_mat, ksize, sigma_x, sigma_y, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_shorts); } else if (ip.getBitDepth() == 32) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); float[] srcdst_floats = (float[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_32F); Mat dst_mat = new Mat(imh, imw, CvType.CV_32F); // run src_mat.put(0, 0, srcdst_floats); Imgproc.GaussianBlur(src_mat, dst_mat, ksize, sigma_x, sigma_y, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_floats); } else { IJ.error("Wrong image format"); } }
From source file:OCV_BilateralFilter.java
License:Open Source License
@Override public void run(ImageProcessor ip) { if (ip.getBitDepth() == 8) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat//from w w w .ja v a 2 s .c om Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.bilateralFilter(src_mat, dst_mat, diameter, sigmaColor, sigmaSpace, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_bytes); } else if (ip.getBitDepth() == 24) { // dst int imw = ip.getWidth(); int imh = ip.getHeight(); int[] srcdst_ints = (int[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC3); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC3); // run OCV__LoadLibrary.intarray2mat(srcdst_ints, src_mat, imw, imh); Imgproc.bilateralFilter(src_mat, dst_mat, diameter, sigmaColor, sigmaSpace, INT_BORDERTYPE[indBorderType]); OCV__LoadLibrary.mat2intarray(dst_mat, srcdst_ints, imw, imh); } else if (ip.getBitDepth() == 32) { // srcdst int imw = ip.getWidth(); int imh = ip.getHeight(); float[] srcdst_bytes = (float[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_32FC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_32FC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.bilateralFilter(src_mat, dst_mat, diameter, sigmaColor, sigmaSpace, INT_BORDERTYPE[indBorderType]); dst_mat.get(0, 0, srcdst_bytes); } else { IJ.error("Wrong image format"); } }
From source file:OCV_EqualizeHist.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // srcdst//from ww w . j a v a2s. c o m int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.equalizeHist(src_mat, dst_mat); dst_mat.get(0, 0, srcdst_bytes); }
From source file:OCV_HoughLinesP.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // src/*from ww w. j a va 2 s .c om*/ int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] src_ar = (byte[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_lines = new Mat(); // run src_mat.put(0, 0, src_ar); Imgproc.HoughLinesP(src_mat, dst_lines, resDist, CV_PI / resAngFact, minVotes, minLen, maxGap); // fin showData(dst_lines); }
From source file:OCV_MedianBlur.java
License:Open Source License
@Override public void run(ImageProcessor ip) { // srcdst//from w w w.j a v a2 s. co m int imw = ip.getWidth(); int imh = ip.getHeight(); byte[] srcdst_bytes = (byte[]) ip.getPixels(); // mat Mat src_mat = new Mat(imh, imw, CvType.CV_8UC1); Mat dst_mat = new Mat(imh, imw, CvType.CV_8UC1); // run src_mat.put(0, 0, srcdst_bytes); Imgproc.medianBlur(src_mat, dst_mat, ksize); dst_mat.get(0, 0, srcdst_bytes); }
From source file:MainPyramids.java
public static void main(String[] args) { try {/*from w w w .j a v a2s. c om*/ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); System.out.println("Verso OPENCV: " + Core.VERSION); //pyramids UP Mat source = Highgui.imread("D:\\teste.png", Highgui.CV_LOAD_IMAGE_COLOR); Mat destinationUp = new Mat(source.rows() * 2, source.cols() * 2, source.type()); destinationUp = source; Imgproc.pyrUp(source, destinationUp, new Size(source.cols() * 2, source.rows() * 2), Imgproc.BORDER_DEFAULT); Highgui.imwrite("D://pyrUp.jpg", destinationUp); //pyramids DOWN source = Highgui.imread("D://teste.png", Highgui.CV_LOAD_IMAGE_COLOR); Mat destinationDown = new Mat(source.rows() / 2, source.cols() / 2, source.type()); destinationDown = source; Imgproc.pyrDown(source, destinationDown, new Size(source.cols() / 2, source.rows() / 2)); Highgui.imwrite("pyrDown.jpg", destinationDown); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } }