Example usage for org.opencv.core Mat eye

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

Introduction

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

Prototype

public static Mat eye(Size size, int type) 

Source Link

Usage

From source file:org.openpnp.vision.FluentCv.java

License:Open Source License

public FluentCv findEdgesRobertsCross(String... tag) {
    // Java interpretation of
    // https://www.scss.tcd.ie/publications/book-supplements/A-Practical-Introduction-to-Computer-Vision-with-OpenCV/Code/Edges.cpp
    // Note: Java API does not have abs. This appears to be doing the
    // same thing effectively, but I am not sure it's 100% the same
    // as Cri's version.
    Mat kernel = Mat.eye(new Size(2, 2), CvType.CV_32FC1);
    kernel.put(0, 0, 0, 1, -1, 0);/*  ww  w.j av a  2  s . c  o  m*/
    Mat roberts1 = new Mat();
    Imgproc.filter2D(mat, roberts1, CvType.CV_32FC1, kernel);
    Core.convertScaleAbs(roberts1, roberts1);

    kernel.put(0, 0, 1, 0, 0, -1);
    Mat roberts2 = new Mat();
    Imgproc.filter2D(mat, roberts2, CvType.CV_32FC1, kernel);
    Core.convertScaleAbs(roberts2, roberts2);

    Mat roberts = new Mat();
    Core.add(roberts1, roberts2, roberts);

    return store(roberts, tag);

    // // Java interpretation of Cri S's C version.
    // // This is very slow, my fault, not his. Probably due to all the
    // // array accesses.
    // int ptr1[] = { 0, 0, 0, 0 };
    // int indexx[] = { 0, 1, 1, 0 };
    // int indexy[] = { 0, 0, 1, 1 };
    // for (int y = 0; y < mat.rows() - 1; y++) {
    // for (int x = 0; x < mat.cols() - 1; x++) {
    // int temp = 0, temp1 = 0;
    // for (int i = 0; i < 4; i++) {
    // ptr1[i] = (int) mat.get(y + indexy[i], x + indexx[i])[0]; // // ptr1[i] = *(ptr + (y +
    // indexy[i]) * gray->widthStep + x + indexx[i]);
    // }
    // temp = Math.abs(ptr1[0] - ptr1[2]);
    // temp1 = Math.abs(ptr1[1] - ptr1[3]);
    // temp = (temp > temp1 ? temp : temp1);
    // temp = (int) Math.sqrt((float) (temp * temp) + (float) (temp1 * temp1));
    // mat.put(y, x, temp); // *(ptr + y * gray->widthStep + x) = temp;
    // }
    // }
    // return store(mat, tag);
}