Example usage for org.opencv.core Mat clone

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

Introduction

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

Prototype

public Mat clone() 

Source Link

Usage

From source file:frmMain.java

/**
 * Creates new form frmMain/*from   www.  jav a 2s. com*/
 */
public frmMain() {
    initComponents();

    File imageFile = new File("D:\\1.jpg");
    //
    System.loadLibrary("opencv_java2412");
    //Opencv ti?n x l
    Mat gray = Highgui.imread(imageFile.getAbsolutePath(), IMREAD_GRAYSCALE);
    Mat result_threholds = gray.clone();
    adaptiveThreshold(gray, result_threholds, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 15, 40);
    frmMain.showResult(result_threholds);
    //Tch OCR
    ITesseract instance = new Tesseract(); // JNA Interface Mapping
    // ITesseract instance = new Tesseract1(); // JNA Direct Mapping
    // instance.setDatapath("<parentPath>"); // replace <parentPath> with path to parent directory of tessdata
    instance.setLanguage("eng");

    try {
        String result = instance.doOCR(imageFile);
        jTextArea1.setText(result);
    } catch (TesseractException e) {
        System.err.println(e.getMessage());
    }
}

From source file:app.GUI2.java

/**
 * this function preproces image to draw helper figures on top of image and
 * then calls updateView()/*  w  ww.java 2s .c  o m*/
 */
private void updateDrawings(Mat unprocesedImage) {
    try {
        image = unprocesedImage.clone();
        // draw Points as circles
        if (pointA1 != null) {
            Imgproc.circle(image, pointA1, 10, new Scalar(0, 0, 128), 2);
        }
        if (pointA2 != null) {
            Imgproc.circle(image, pointA2, 10, new Scalar(0, 0, 255), 2);
        }
        if (pointB1 != null) {
            Imgproc.circle(image, pointB1, 10, new Scalar(128, 0, 0), 2);
        }
        if (pointB2 != null) {
            Imgproc.circle(image, pointB2, 10, new Scalar(255, 0, 0), 2);
        }
        // draw rectangles of selected circles
        if (pointA1 != null & pointA2 != null) {
            Imgproc.rectangle(image, pointA1, pointA2, new Scalar(0, 0, 255), 2);
        }
        if (pointB1 != null & pointB2 != null) {
            Imgproc.rectangle(image, pointB1, pointB2, new Scalar(255, 0, 0), 2);
        }

        updateView(image);
    } catch (Exception e) {
        System.err.println("Tryied to Draw without loading image" + e);
    }

}

From source file:at.ac.tuwien.caa.docscan.camera.CameraPreview.java

License:Open Source License

private void checkMovementAfterCapture(byte[] pixels) {

    long timePassed = System.currentTimeMillis() - mVerificationTime;
    if (timePassed <= VERIFICATION_TIME_DIFF) {

        Mat mat = byte2Mat(pixels);

        ChangeCallable cCallable = new ChangeCallable(mat.clone(), mCVCallback, mTimerCallbacks);
        mCVThreadManager.addCallable(cCallable, CVThreadManager.TASK_CHANGE);
        boolean isSteady = mCVThreadManager.isFrameSteadyAndNew();
        if (!isSteady)
            mVerifyCapture = false;/* w  ww  .ja v a2s  .  c om*/
        return;

    } else {
        mVerifyCapture = false;
        mCVCallback.onCaptureVerified();
        return;
    }

}

From source file:at.ac.tuwien.caa.docscan.camera.CameraPreview.java

License:Open Source License

private void performCVTasks(byte[] pixels) {

    long currentTime = System.currentTimeMillis();

    if (currentTime - mLastTime >= FRAME_TIME_DIFF) {

        //        if (true) {
        Mat mat = byte2Mat(pixels);

        if (mStoreMat) {
            ChangeDetector.initMovementDetector(mat);
            ChangeDetector.initNewFrameDetector(mat);
            mStoreMat = false;//from   w w w  .j av  a2 s .c  om
        } else if (!ChangeDetector.isMovementDetectorInitialized()) {
            ChangeDetector.initMovementDetector(mat);
        }

        boolean processFrame = true;
        // In serial mode the document analysis is just performed if no movement occurred:
        if (mAwaitFrameChanges) {
            if (!mCVThreadManager.isRunning(CVThreadManager.TASK_CHANGE)) {
                ChangeCallable cCallable = new ChangeCallable(mat.clone(), mCVCallback, mTimerCallbacks);
                mCVThreadManager.addCallable(cCallable, CVThreadManager.TASK_CHANGE);
                processFrame = mCVThreadManager.isFrameSteadyAndNew();
            }
        }

        if (processFrame) {

            mTimerCallbacks.onTimerStarted(TaskTimer.TaskType.MOVEMENT_CHECK);
            Mat mat2 = mat.clone();
            mTimerCallbacks.onTimerStopped(TaskTimer.TaskType.MOVEMENT_CHECK);

            if (!mCVThreadManager.isRunning(CVThreadManager.TASK_PAGE)) {
                PageCallable pCallable = new PageCallable(mat.clone(), mCVCallback, mTimerCallbacks, mFrameCnt);
                mCVThreadManager.addCallable(pCallable, CVThreadManager.TASK_PAGE);
            }

            if (mMeasureFocus && !mCVThreadManager.isRunning(CVThreadManager.TASK_FOCUS)) {
                FocusCallable fCallable = new FocusCallable(mat.clone(), mCVCallback, mTimerCallbacks);
                mCVThreadManager.addCallable(fCallable, CVThreadManager.TASK_FOCUS);
            }

            if (mAwaitFrameChanges)
                mVerificationTime = System.currentTimeMillis();

        }

        mat.release();

        mLastTime = currentTime;

    }

}

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();//w w w .j a  va  2  s  .com
    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.Analizador.java

public BufferedImage analizarMelanoma(Mat img) {
    int totalP, areaM, tamImg = img.width() * img.height();
    Mat imagenCopia = img.clone();
    Mat imagenCopia1 = img.clone();/*from w  ww.  j  av  a  2  s .  c o m*/
    img = segmentador.dameLaDona(img);
    Mat img2 = segmentador.dameLaDona(imagenCopia);
    img2 = segmentador.descompCanImg(img2, 1);
    img2 = segmentador.umbralizarImg(img2, 254, 255);

    img = segmentador.blurearImg(img, 25);
    img = segmentador.descompCanImg(img, 1);
    //Ventana v = new Ventana(convertir(img2), 0, 0);
    totalP = tamImg - countNonZero(img2);

    img = segmentador.umbralizarImg(img, 30, 150);
    img = segmentador.umbralizarImg(img, 0, 255);
    areaM = tamImg - countNonZero(img);
    resultadoMelanoma = (areaM * 100) / (double) totalP;
    resultadoMelanoma = (double) ((int) (resultadoMelanoma * 100.00) / 100);
    System.out.println("El area afectada por melanoma es: " + resultadoMelanoma + "%");
    System.out.println("El area de iris abarca: " + totalP);
    System.out.println("El total de pixeles es: " + tamImg);
    addWeighted(segmentador.descompCanImg(imagenCopia1, 2), 1, img, 0.3, 0.0, img);
    //Ventana v1 = new Ventana(segmentador.convertir(img), 1, 0);

    return segmentador.Mat2BufferedImage(img);
}

From source file:Clases.Segmentador.java

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

    Size sizeA = img1.size();/*www  . j a  v a 2  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  ww  .j a  va2s  .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 Mat eriosionarImg(Mat umbralizada) {
    Mat dste = umbralizada.clone();
    int erosion_size = 5;
    Size s = new Size(2 * erosion_size + 1, 2 * erosion_size + 1);
    Point p = new Point(erosion_size, erosion_size);
    Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, s, p);
    Imgproc.erode(umbralizada, dste, element);
    return dste;/*from  w  ww . j  a  v a  2s.  c om*/
}

From source file:Clases.Segmentador.java

public Mat dilatarImg(Mat umbralizada) {
    Mat dstd = umbralizada.clone();
    int dilatacion_size = 5;
    Size sd = new Size(2 * dilatacion_size + 1, 2 * dilatacion_size + 1);
    Point pd = new Point(dilatacion_size, dilatacion_size);
    Mat elementd = Imgproc.getStructuringElement(Imgproc.MORPH_ELLIPSE, sd, pd);
    Imgproc.dilate(umbralizada, dstd, elementd);
    return dstd;/*w  w w.  ja  v  a2 s  .  c  o  m*/
}