Example usage for org.opencv.core Mat rows

List of usage examples for org.opencv.core Mat rows

Introduction

In this page you can find the example usage for org.opencv.core Mat rows.

Prototype

public int rows() 

Source Link

Usage

From source file:jarvis.module.colourtracking.Mat2Image.java

public void getSpace(Mat mat) {
    this.mat = mat;
    int w = mat.cols(), h = mat.rows();
    if (dat == null || dat.length != w * h * 3)
        dat = new byte[w * h * 3];
    if (img == null || img.getWidth() != w || img.getHeight() != h
            || img.getType() != BufferedImage.TYPE_3BYTE_BGR)
        img = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
}

From source file:jarvis.module.colourtracking.Mat2Image.java

BufferedImage getImage(Mat mat) {
    //----------Additional line-----------------------------------------------------
    Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGB2BGR);
    //------------------------------------------------------------------------------
    getSpace(mat);//from   w  w  w. ja va  2 s. c  om
    mat.get(0, 0, dat);
    img.getRaster().setDataElements(0, 0, mat.cols(), mat.rows(), dat);
    return img;
}

From source file:javaapplication1.Ocv.java

void directManip(String input, String output) {
    // load the image and read it into a matrix
    File f2 = new File(input);
    Mat image = Highgui.imread(this.input);

    // we're know we're working in 24-bit color dept, so prepare a 3-byte
    // array for storing cells from the Matrix
    byte[] vec3 = new byte[3];

    // Note: we are traversing every other column and every other row
    for (int i = 0; i < image.cols(); i += 2) {
        for (int j = 0; j < image.rows(); j += 2) {
            // get pixel, just to show how to get pixels...
            image.get(j, i, vec3);/*ww w  .j  a  v  a 2  s . co m*/
            // create a zero pixel
            for (int z = 0; z < 3; ++z)
                vec3[z] = 0;
            // set the current pixel to zero
            image.put(j, i, vec3);
        }
    }

    // output the file
    Highgui.imwrite(this.output, image);
}

From source file:javacv.JavaCV.java

/**
 * Converts/writes a Mat into a BufferedImage.
 *
 * @param matrix Mat of type CV_8UC3 or CV_8UC1
 * @return BufferedImage of type TYPE_3BYTE_BGR or TYPE_BYTE_GRAY
 *///from  w  w w.  ja v  a2 s. com
public static 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;
    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 image2 = new BufferedImage(cols, rows, type);
    image2.getRaster().setDataElements(0, 0, cols, rows, data);
    return image2;
}

From source file:javafx1.JavaFX1.java

public Image bildLaden() {
        Image zwischenBild = null;

        try {/*w  w  w  .j  a  v  a2  s. c o  m*/
            File input = new File("D:/_piCam/bild.jpg");
            //FileInputStream bi = ImageIO.read(input);
            BufferedImage bi = ImageIO.read(input);

            byte[] data = ((DataBufferByte) bi.getRaster().getDataBuffer()).getData();
            Mat mat = new Mat(bi.getHeight(), bi.getWidth(), CvType.CV_8UC3);
            mat.put(0, 0, data);

            Mat bild = new Mat(bi.getHeight(), bi.getWidth(), CvType.CV_8UC1);
            Imgproc.cvtColor(mat, bild, Imgproc.COLOR_BGR2GRAY);

            byte[] data1 = new byte[bild.rows() * bild.cols() * (int) (bild.elemSize())];
            bild.get(0, 0, data1);
            BufferedImage image1 = new BufferedImage(bild.cols(), bild.rows(), BufferedImage.TYPE_BYTE_GRAY);
            image1.getRaster().setDataElements(0, 0, bild.cols(), bild.rows(), data1);

            File ouptut = new File("D:/xml/grayscale2.jpg");
            //ImageIO.write(image1, "jpg", ouptut);
            BufferedImage gray = image1.getSubimage(0, 0, image1.getTileWidth(), image1.getHeight());
            zwischenBild = SwingFXUtils.toFXImage(gray, null);

        } catch (IOException ex) {
            System.out.println("Fehler beim Bild laden...");
        }
        return zwischenBild;
    }

From source file:kamerka.Filters.java

public void sharpness(String sourcePath, int a, int b, int g) {
    double alpha = (double) a / 100;
    double beta = (double) b / 100;
    double gamma = (double) g / 100;
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat source = Highgui.imread(sourcePath, Highgui.CV_LOAD_IMAGE_COLOR);
    Mat destination = new Mat(source.rows(), source.cols(), source.type());
    Imgproc.GaussianBlur(source, destination, new Size(0, 0), 10);
    Core.addWeighted(source, alpha, destination, beta, gamma, destination);
    Highgui.imwrite(sourcePath, destination);
}

From source file:kamerka.Filters.java

public void border(String sourcePath, int s, int borderType) {
    if (borderType == -1) {
        return;// w  w w . ja v  a2 s.  c  o  m
    }
    if (borderType == 5) {
        borderType = 16;
    }
    double size = (double) s / 100;
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat source = Highgui.imread(sourcePath, Highgui.CV_LOAD_IMAGE_COLOR);
    Mat destination = new Mat(source.rows(), source.cols(), source.type());
    int top, bottom, left, right;
    top = (int) (size * source.rows());
    bottom = (int) (size * source.rows());
    left = (int) (size * source.cols());
    right = (int) (size * source.cols());
    destination = source;
    Imgproc.copyMakeBorder(source, destination, top, bottom, left, right, borderType);
    Highgui.imwrite(sourcePath, destination);
}

From source file:kamerka.Filters.java

public void thresholding(String sourcePath, int thesh, int type) {
    if (type == -1) {
        return;/* ww  w . j  av a2s  . co  m*/
    }
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat source = Highgui.imread(sourcePath, Highgui.CV_LOAD_IMAGE_COLOR);
    Mat destination = new Mat(source.rows(), source.cols(), source.type());
    destination = source;
    Imgproc.threshold(source, destination, thesh, 255, type);
    Highgui.imwrite(sourcePath, destination);
}

From source file:kamerka.Filters.java

public void flip(String sourcePath, int code) {
    if (code == -1)
        return;//from w  w w . j a  v  a  2 s  .c o m
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat source = Highgui.imread(sourcePath, Highgui.CV_LOAD_IMAGE_COLOR);
    Mat destination = new Mat(source.rows(), source.cols(), source.type());
    destination = source;
    Core.flip(source, source, code);
    Highgui.imwrite(sourcePath, destination);
}

From source file:kamerka.Filters.java

public void gaussian(String sourcePath, int size) {
    try {// w  w w.j a  va2s  .co m
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat source = Highgui.imread(sourcePath, Highgui.CV_LOAD_IMAGE_COLOR);
        Mat destination = new Mat(source.rows(), source.cols(), source.type());
        destination = source;
        if (size % 2 == 0)
            size++;
        Imgproc.GaussianBlur(source, destination, new Size(size, size), 0);
        Highgui.imwrite(sourcePath, destination);
    } catch (Exception e) {
        System.out.println("Error in gaussian func" + e.getMessage());
    }
}