Example usage for org.opencv.core Mat get

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

Introduction

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

Prototype

public double[] get(int row, int col) 

Source Link

Usage

From source file:ch.zhaw.facerecognitionlibrary.Recognition.Eigenfaces.java

License:Open Source License

public String recognize(Mat img, String expectedLabel) {
    // Ignore//  w  w  w. j  a  v  a2s  .  c om
    img = img.reshape(1, 1);
    // Subtract mean
    img.convertTo(img, CvType.CV_32F);
    Core.subtract(img, Psi, img);
    // Project to subspace
    Mat projected = getFeatureVector(img);
    // Save all points of image for tSNE
    img.convertTo(img, CvType.CV_8U);
    addImage(projected, expectedLabel, true);
    //addImage(projected, expectedLabel);
    Mat distance = new Mat(Omega.rows(), 1, CvType.CV_64FC1);
    for (int i = 0; i < Omega.rows(); i++) {
        double dist = Core.norm(projected.row(0), Omega.row(i), Core.NORM_L2);
        distance.put(i, 0, dist);
    }
    Mat sortedDist = new Mat(Omega.rows(), 1, CvType.CV_8UC1);
    Core.sortIdx(distance, sortedDist, Core.SORT_EVERY_COLUMN + Core.SORT_ASCENDING);
    // Give back the name of the found person
    int index = (int) (sortedDist.get(0, 0)[0]);
    return labelMap.getKey(labelList.get(index));
}

From source file:ch.zhaw.facerecognitionlibrary.Recognition.SupportVectorMachine.java

License:Open Source License

private String imageToSvmString(Mat img, String label) {
    int iLabel = 0;
    if (method == TRAINING) {
        if (labelMap.containsKey(label)) {
            iLabel = labelMap.getValue(label);
        } else {//from  w ww . j a  v  a 2 s  .c o  m
            iLabel = labelMap.size() + 1;
            labelMap.put(label, iLabel);
        }
    } else {
        if (labelMapTest.containsKey(label)) {
            iLabel = labelMapTest.getValue(label);
        } else {
            iLabel = labelMapTest.size() + 1;
            labelMapTest.put(label, iLabel);
        }
    }
    String result = String.valueOf(iLabel);
    img = getFeatureVector(img);
    for (int i = 0; i < img.cols(); i++) {
        result = result + " " + i + ":" + img.get(0, i)[0];
    }
    result += "\n";
    return result;
}

From source file:Clases.Analizador.java

public BufferedImage analizarCatarata(Mat img) {
    double[] pupila = segmentador.segmentarPupila(img);
    double[] clase = { 99.8125, 150.7500, 150.8125 };
    double areaPupila = Math.PI * Math.pow(pupila[2], 2);
    int acumulador = 0;
    //Core.circle(img, new Point(pupila[0], pupila[1]), (int) pupila[2], new Scalar(255, 0, 0), 3);
    //Ventana v1 = new Ventana(convertir(max), 1, 0);
    //Ventana v2 = new Ventana(convertir(img), 3, 0);
    Size sizeA = img.size();/*from  w  w  w.j  a va 2  s  .  co  m*/
    Mat max = img.clone();

    double[] data;
    for (int i = 0; i < sizeA.height; i++) {
        for (int j = 0; j < sizeA.width; j++) {
            if ((Math.pow(pupila[0] - j, 2) + Math.pow(pupila[1] - i, 2) <= Math.pow(pupila[2], 2))) {
                data = img.get(i, j);
                double res = Math.sqrt(Math.pow(clase[0] - data[2], 2) + Math.pow(clase[1] - data[1], 2)
                        + Math.pow(clase[2] - data[0], 2));
                if (res < 60) {
                    data[0] = 0;
                    data[1] = 255;
                    data[2] = 0;
                    acumulador++;
                }
                max.put(i, j, data);
            }
        }
    }
    resultadoCatarata = (acumulador * 100) / areaPupila;
    resultadoCatarata = (double) ((int) (resultadoCatarata * 100.00) / 100);
    //Core.circle(imagen, new Point(pupila[0], pupila[1]), (int) pupila[2], new Scalar(255, 0, 0), 3);
    //Ventana v1 = new Ventana(segmentador.convertir(max), 0, 0);
    //Ventana v2 = new Ventana(convertir(imagen), 2, 0);
    return segmentador.Mat2BufferedImage(max);
}

From source file:Clases.Segmentador.java

public Mat detectaPterigion(Mat img_ana, int val1, int val2, int val3) {
    int r = 200, g = 125, b = 115;
    for (int y = 0; y < img_ana.rows(); y++) {
        for (int x = 0; x < img_ana.cols(); x++) {
            double[] color = img_ana.get(y, x);
            if (color[2] >= r - val1 && color[2] <= r + val1 && color[1] >= g - val2 && color[1] <= g + val2
                    && color[0] >= b - val3 && color[0] <= b + val3) {
                color[0] = 0;//from   w  w  w.  j av  a  2s.c  om
                color[1] = 255;
                color[2] = 255;
            }
            img_ana.put(y, x, color);
        }
    }
    return img_ana;
}

From source file:Clases.Segmentador.java

public int detectaEsclerotica(Mat img_ana, int val1, int val2, int val3) {
    int r = 190, g = 187, b = 181, area = 0;
    for (int y = 0; y < img_ana.rows(); y++) {
        for (int x = 0; x < img_ana.cols(); x++) {
            double[] color = img_ana.get(y, x);
            if (color[2] >= r - val1 && color[2] <= r + val1 && color[1] >= g - val2 && color[1] <= g + val2
                    && color[0] >= b - val3 && color[0] <= b + val3) {
                area++;/*from   w  w  w  .  ja  v  a  2s. c  o  m*/
            }
            img_ana.put(y, x, color);
        }
    }
    return area;
}

From source file:Clases.Segmentador.java

public int detectaAreaPterigion(Mat img_ana) {
    int area = 0;
    for (int y = 0; y < img_ana.rows(); y++) {
        for (int x = 0; x < img_ana.cols(); x++) {
            double[] color = img_ana.get(y, x);
            if (color[2] == 255 && color[1] == 255 && color[0] == 0) {
                area++;/*  w w  w. ja  v  a2 s .c  o m*/
            }
        }
    }
    return area;
}

From source file:Clases.Segmentador.java

public Mat dameLaDona(Mat img1) {
    double[] iris = segmentarIris(img1);
    double[] pupila = segmentarPupila(img1);

    Size sizeA = img1.size();/* w  w  w  .j a v  a2  s.  c o  m*/
    Mat max = img1.clone();

    double[] data;
    for (int i = 0; i < sizeA.height; i++) {
        for (int j = 0; j < sizeA.width; j++) {
            if ((Math.pow(iris[0] - j, 2) + Math.pow(iris[1] - i, 2) >= Math.pow(iris[2], 2))
                    || (Math.pow(pupila[0] - j, 2) + Math.pow(pupila[1] - i, 2) <= Math.pow(pupila[2], 2))) {
                data = img1.get(i, j);
                data[0] = 255;
                data[1] = 255;
                data[2] = 255;
                max.put(i, j, data);
            }

        }
    }
    return max;
}

From source file:Clases.Segmentador.java

public Mat limitaIris(Mat img1) {

    double[] iris = segmentarIris(img1);
    iris[2] = iris[2] * 0.8;/*from   w  w w . ja  v a  2s  .c o m*/
    Size sizeA = img1.size();
    Mat max = img1.clone();

    double[] data;
    for (int i = 0; i < sizeA.height; i++) {
        for (int j = 0; j < sizeA.width; j++) {
            if ((Math.pow(iris[0] - j, 2) + Math.pow(iris[1] - i, 2) >= Math.pow(iris[2], 2))) {
                data = img1.get(i, j);
                data[0] = 255;
                data[1] = 255;
                data[2] = 255;
                max.put(i, j, data);
            }

        }
    }
    return max;
}

From source file:Clases.Segmentador.java

public double[] TransfHough(Mat edges, int inv, int distMinCir, int umbMin, int umbMax, int radMin,
        int radMax) {

    Mat circles = new Mat();
    double[] data = null;
    //Vector<Mat> circlesList = new Vector<Mat>();
    Imgproc.HoughCircles(edges, circles, Imgproc.CV_HOUGH_GRADIENT, inv, distMinCir, umbMin, umbMax, radMin,
            radMax);//  w  w  w  .j  av a  2 s  .  c  o m
    //Imgproc.HoughCircles(edges, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 200, 1, 10, 20, 40  );
    //Imgproc.HoughCircles(edges, circles, Imgproc.CV_HOUGH_GRADIENT, 1, 50) ;

    System.out.println("#rows " + circles.rows() + " #cols " + circles.cols());
    double x = 0.0;
    double y = 0.0;
    int r = 0;

    for (int i = 0; i < circles.rows(); i++) {
        data = circles.get(i, 0);
        for (int j = 0; j < data.length; j++) {
            x = data[0];
            y = data[1];
            r = (int) data[2];
        }
        Point center = new Point(x, y);

        // circle center
        //            Core.circle(color, center, 1, new Scalar(0, 0, 0), -1);
        // circle outline
        //          Core.circle(color, center, r, new Scalar(0, 255, 0), 1);
        //Ventana ventana8 = new Ventana(convertir((color)),0,2);
        //ventana8.setTitle("Houg");
        /*
         Rect bbox = new Rect((int)Math.abs(x-r), (int)Math.abs(y-r), (int)2*r, (int)2*r);
         Mat croped_image = new Mat(color, bbox);
         Imgproc.resize(croped_image, croped_image, new Size(200,200));
         circlesList.add(croped_image);
         Ventana ventana9 = new Ventana(convertir(croped_image),1,2);
         */
    }

    return data;
}

From source file:classes.TextExtractor.java

private static Point transformPoint(Point point, Mat transformationMatrix) {
    double newX = transformationMatrix.get(0, 0)[0] * point.x + transformationMatrix.get(0, 1)[0] * point.y
            + transformationMatrix.get(0, 2)[0];
    double newY = transformationMatrix.get(1, 0)[0] * point.x + transformationMatrix.get(1, 1)[0] * point.y
            + transformationMatrix.get(1, 2)[0];
    return new Point(newX, newY);
}