List of usage examples for org.opencv.core Mat rows
public int rows()
From source file:OCV_GetRotationMatrix2D.java
License:Open Source License
@Override public void run(ImageProcessor ip) { Mat mat = Imgproc.getRotationMatrix2D(new Point(center_x, center_y), angle, scale); if (mat == null || mat.rows() <= 0 || mat.cols() <= 0) { IJ.showMessage("Output is null or error"); return;//w w w.j a va 2 s .c o m } ResultsTable rt = OCV__LoadLibrary.GetResultsTable(true); rt.incrementCounter(); rt.addValue("Column01", String.valueOf(mat.get(0, 0)[0])); rt.addValue("Column02", String.valueOf(mat.get(0, 1)[0])); rt.addValue("Column03", String.valueOf(mat.get(0, 2)[0])); rt.incrementCounter(); rt.addValue("Column01", String.valueOf(mat.get(1, 0)[0])); rt.addValue("Column02", String.valueOf(mat.get(1, 1)[0])); rt.addValue("Column03", String.valueOf(mat.get(1, 2)[0])); rt.show("Results"); }
From source file:ImagetoPDF.java
public static void enhance(String fileName) throws IOException { Mat source = Imgcodecs.imread(fileName, Imgcodecs.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows(), source.cols(), source.type()); // Imgproc.cvtColor(source, destination, Imgproc.COLOR_BGR2GRAY); Imgproc.cvtColor(source, source, Imgproc.COLOR_BGR2GRAY); Mat imageMat = source;//ww w . j a v a 2s .co m Imgproc.GaussianBlur(imageMat, imageMat, new Size(3, 3), 0); Imgproc.adaptiveThreshold(imageMat, imageMat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 5, 4); Imgcodecs.imwrite(fileName, imageMat); }
From source file:MainBorder.java
public static void main(String[] args) { try {/*from w ww.j a v a 2s. com*/ 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()); int top, bottom, left, right; int borderType; //initialize arguments for the filter border top = (int) (0.05 * source.rows()); bottom = (int) (0.05 * source.rows()); left = (int) (0.15 * source.cols()); right = (int) (0.15 * source.cols()); destination = source; //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_WRAP); //borda com a imagem //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_CONSTANT); //borda preta Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_DEFAULT); //borda transparente //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_ISOLATED); // borda escura?? //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_REFLECT); //borda com reflexo da prpria imagem //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_REFLECT101); //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_REFLECT_101); //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_REPLICATE); //borda efeito movimento //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_TRANSPARENT); //borda no funciona Highgui.imwrite("D:\\borderWrap.jpg", destination); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } }
From source file:MainEroding.java
public static void main(String[] args) { try {/* w w w . ja va 2s. c om*/ int erosion_size = 2; //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 * erosion_size + 1, 2 * erosion_size + 1)); Imgproc.erode(source, destination, element); Highgui.imwrite("D://Erosion.jpg", destination); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } }
From source file:MainGaussian.java
public static void main(String[] args) { try {//www.j av a 2 s . c o m 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()); Imgproc.GaussianBlur(source, destination, new Size(45, 45), 0); //Imgproc.GaussianBlur(source, destination, new Size(65,65), 0); //Imgproc.GaussianBlur(source, destination, new Size(25,1), 0); Highgui.imwrite("D://Gaussian45.jpg", destination); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } }
From source file:OCV_HoughLines.java
License:Open Source License
private void showData(Mat lines, int imw, int imh) { // prepare the ResultsTable ResultsTable rt = OCV__LoadLibrary.GetResultsTable(true); // prepare the ROI Manager RoiManager roiMan = null;//w w w . j a v a2s . co m if (enAddRoi) { roiMan = OCV__LoadLibrary.GetRoiManager(true, true); } // show int num_lines = lines.rows(); float[] res = new float[2]; for (int i = 0; i < num_lines; i++) { lines.get(i, 0, res); float rho = res[0]; float theta = res[1]; double a = Math.cos(theta); double b = Math.sin(theta); double x0 = a * rho; double y0 = b * rho; double z = imw < imh ? imh : imw; double x1 = x0 + z * (-b); double y1 = y0 + z * a; double x2 = x0 - z * (-b); double y2 = y0 - z * (a); rt.incrementCounter(); rt.addValue("rho", rho); rt.addValue("theta", theta); rt.addValue("z", z); rt.addValue("x1", x1); rt.addValue("y1", y1); rt.addValue("x2", x2); rt.addValue("y2", y2); if (enAddRoi && (roiMan != null)) { Line roi = new Line(x1, y1, x2, y2); roiMan.addRoi(roi); } } rt.show("Results"); }
From source file:MainShapeConversion.java
public static void main(String[] args) { try {//from www . j a v a 2 s . c om System.loadLibrary(Core.NATIVE_LIBRARY_NAME); File input = new File("D://teste.png"); BufferedImage image = ImageIO.read(input); byte[] data = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); Mat mat = new Mat(image.getHeight(), image.getWidth(), CvType.CV_8UC3); mat.put(0, 0, data); Mat mat1 = new Mat(image.getWidth(), image.getHeight(), CvType.CV_8UC3); Core.flip(mat, mat1, -1); //-1 invert , 1 normal byte[] data1 = new byte[mat1.rows() * mat1.cols() * (int) (mat1.elemSize())]; mat1.get(0, 0, data1); BufferedImage image1 = new BufferedImage(mat1.cols(), mat1.rows(), 5); image1.getRaster().setDataElements(0, 0, mat1.cols(), mat1.rows(), data1); File output = new File("D://hsv.jpg"); ImageIO.write(image1, "jpg", output); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } }
From source file:Video.java
public BufferedImage matToBufferedImage(Mat matrix) { int cols = matrix.cols(); int rows = matrix.rows(); int elemSize = (int) matrix.elemSize(); byte[] data = new byte[cols * rows * elemSize]; int type;//from ww w . j ava 2 s . co m matrix.get(0, 0, data); switch (matrix.channels()) { case 1: type = BufferedImage.TYPE_BYTE_GRAY; break; case 3: type = BufferedImage.TYPE_3BYTE_BGR; // bgr to rgb byte b; for (int i = 0; i < data.length; i = i + 3) { b = data[i]; data[i] = data[i + 2]; data[i + 2] = b; } break; default: return null; } BufferedImage image = new BufferedImage(cols, rows, type); image.getRaster().setDataElements(0, 0, cols, rows, data); return image; }
From source file:MainThresholding.java
public static void main(String[] args) { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); try {//w w w.j a va 2s .c o m Mat source = Highgui.imread("D://teste.png", Highgui.CV_LOAD_IMAGE_COLOR); Mat destination = new Mat(source.rows(), source.cols(), source.type()); destination = source; //Imgproc.threshold(source, destination, 125, 255, Imgproc.THRESH_TOZERO); //Imgproc.threshold(source, destination, 125, 255, Imgproc.THRESH_BINARY); //Imgproc.threshold(source, destination, 125, 255, Imgproc.THRESH_BINARY_INV); //Imgproc.threshold(source, destination, 125, 255, Imgproc.THRESH_TOZERO_INV); Imgproc.threshold(source, destination, 125, 255, Imgproc.THRESH_TRUNC); Highgui.imwrite("D://ThreshZero.jpg", destination); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } }
From source file:PutFiltro.java
public static Mat mainBorda(Mat source) { Mat destination = new Mat(source.rows(), source.cols(), source.type()); try {/*from ww w. j a v a 2 s.c o m*/ //System.loadLibrary(Core.NATIVE_LIBRARY_NAME); /* Mat source = Highgui.imread("D:\\teste.png", Highgui.CV_LOAD_IMAGE_COLOR); */ int top, bottom, left, right; int borderType; //initialize arguments for the filter border top = (int) (0.05 * source.rows()); bottom = (int) (0.05 * source.rows()); left = (int) (0.15 * source.cols()); right = (int) (0.15 * source.cols()); destination = source; //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_WRAP); //borda com a imagem Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_CONSTANT); //borda preta //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_DEFAULT); //borda transparente //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_ISOLATED); // borda escura?? //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_REFLECT); //borda com reflexo da prpria imagem //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_REFLECT101); //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_REFLECT_101); //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_REPLICATE); //borda efeito movimento //Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, Imgproc.BORDER_TRANSPARENT); //borda no funciona //Highgui.imwrite("D:\\borderWrap.jpg", destination); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } return destination; }