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:simeav.filtros.instanciaciones.DetectorModulosEstandar.java

@Override
public Mat detectarModulos(Mat original, Diagrama diagrama) {
    Imgproc.blur(original, original, new Size(15, 15));
    original = Utils.dilate(original);/*  www. j  a va  2  s  . c om*/
    Mat jerarquia = new Mat();
    ArrayList<MatOfPoint> contornos = new ArrayList<>();
    Imgproc.findContours(original.clone(), contornos, jerarquia, Imgproc.RETR_CCOMP,
            Imgproc.CHAIN_APPROX_SIMPLE);
    ArrayList<MatOfPoint> cp = new ArrayList<>(contornos.size());
    Map<Integer, Rect> rectangulos = new HashMap<>();
    Integer id_cuadrado = 0;
    Mat resultado = Mat.zeros(original.size(), CvType.CV_8U);
    for (int i = contornos.size() - 1; i >= 0; i--) {
        if (jerarquia.get(0, i)[3] > -1) {
            MatOfPoint2f contorno2f = new MatOfPoint2f();
            contorno2f.fromList(contornos.get(i).toList());
            MatOfPoint2f c = new MatOfPoint2f();
            Imgproc.approxPolyDP(contorno2f, c, 3, true);
            cp.add(new MatOfPoint(c.toArray()));
            int lados = cp.get(cp.size() - 1).height();
            if ((4 <= lados) && lados < 12) {
                rectangulos.put(id_cuadrado, Imgproc.boundingRect(new MatOfPoint(c.toArray())));
                Point tl = new Point(rectangulos.get(id_cuadrado).tl().x - 20,
                        rectangulos.get(id_cuadrado).tl().y - 20);
                Point br = new Point(rectangulos.get(id_cuadrado).br().x + 20,
                        rectangulos.get(id_cuadrado).br().y + 20);
                Core.rectangle(resultado, tl, br, new Scalar(255, 255, 255), -1);
                diagrama.addModulo(id_cuadrado, new Rect(tl, br));
                Imgproc.drawContours(resultado, contornos, i, new Scalar(0, 0, 0), -1);
                id_cuadrado++;
            }
        }
    }
    return resultado;
}

From source file:simeav.filtros.instanciaciones.SeparadorTextoEstandar.java

@Override
public void separarTexto(Mat origin, int umbral_radio) {
    Mat original = origin.clone();
    imagenSinTexto = original.clone();//from w w w.j  a v a 2 s .  c  o  m
    imagenTexto = Mat.zeros(original.size(), CvType.CV_8U);
    imagenTexto = imagenTexto.setTo(new Scalar(255, 255, 255));
    Mat imGrises = new Mat();
    Mat bw = new Mat();
    Imgproc.cvtColor(original, imGrises, Imgproc.COLOR_BGR2GRAY);
    Imgproc.GaussianBlur(imGrises, bw, new Size(1, 1), 0);
    Imgproc.threshold(bw, bw, 200, 250, Imgproc.THRESH_BINARY_INV);
    ArrayList<MatOfPoint> contornos = Utils.detectarContornos(bw);
    for (int i = 0; i < contornos.size(); i++) {
        MatOfPoint2f contorno2f = new MatOfPoint2f();
        contorno2f.fromList(contornos.get(i).toList());
        float[] radius = new float[1];
        Point centro = new Point();
        Imgproc.minEnclosingCircle(contorno2f, centro, radius);
        double a = Imgproc.contourArea(contornos.get(i));
        if (radius[0] <= umbral_radio) {
            Imgproc.drawContours(imagenSinTexto, contornos, i, new Scalar(255, 255, 255), -1);
            Imgproc.drawContours(imagenTexto, contornos, i, new Scalar(0, 0, 0), -1);
        }
    }
}

From source file:simeav.Utils.java

public static ArrayList<MatOfPoint> detectarContornos(Mat original) {
    Mat jerarquia = new Mat();
    ArrayList<MatOfPoint> contornos = new ArrayList<>();
    Imgproc.findContours(original.clone(), contornos, jerarquia, Imgproc.RETR_TREE,
            Imgproc.CHAIN_APPROX_SIMPLE);
    return contornos;
}

From source file:simeav.Utils.java

public static ArrayList<Point> detectarVertices(Mat original) {
    MatOfPoint corners = new MatOfPoint();
    Imgproc.goodFeaturesToTrack(original, corners, 100, 0.01, 0, new Mat(), 2, false, 0.04);
    Mat vertices = Mat.zeros(original.size(), CvType.CV_8UC3);
    for (int i = 0; i < corners.height(); i++) {
        Core.circle(vertices, new Point(corners.get(i, 0)), 8, new Scalar(180, 170, 5), -1);
    }/* w  w  w  . j ava 2s .  c  o  m*/

    Mat imGrises = new Mat();
    Mat bw = new Mat();
    Imgproc.cvtColor(vertices, imGrises, Imgproc.COLOR_BGR2GRAY);
    Imgproc.Canny(imGrises, bw, 100, 150, 5, true);

    Mat jerarquia = new Mat();
    ArrayList<MatOfPoint> contornos = new ArrayList<>();
    Imgproc.findContours(bw.clone(), contornos, jerarquia, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
    ArrayList<Point> mc = Utils.getCentros(contornos);
    Mat resultado = Mat.zeros(original.size(), CvType.CV_8UC3);
    for (int i = 0; i < contornos.size(); i++) {
        Scalar color = new Scalar(180, 170, 5);
        //            Imgproc.drawContours(resultado, contornos, i, color, 2, 8, jerarquia, 0, new Point());
        Core.circle(resultado, mc.get(i), 4, color, -1, 8, 0);
    }
    return mc;
}

From source file:singleOperations.CalculateArea.java

public static void main(String[] args) {
    //cargamos los elementos de la libreria nativa
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    //Leemos un archivo de imagen
    Mat image = Highgui.imread("camera/imageCamera.png", Highgui.CV_LOAD_IMAGE_COLOR);
    Mat imageHSV = image.clone();
    //cargamos la imagen a una ventana
    ImageProccessingFrame pi = new ImageProccessingFrame("Example");
    pi.displayImageProccessed(image);//from   w ww .j a  v a2s .  c  o  m

    //        //Algoritmo para preprocesar la imagen: formato HSV
    //        Imgproc.cvtColor(image, imageHSV, Imgproc.COLOR_RGB2HSV);

    IPColorHSVChannels colorHSVChannels = new IPColorHSVChannels("EXampleHSV", MyStrings.channelsHSVNames);
    colorHSVChannels.displayImageProccessed(imageHSV);

    IPColorRGBChannels colorRGBChannels = new IPColorRGBChannels("EcampleRGB", MyStrings.channelsNames);
    colorRGBChannels.displayImageProccessed(imageHSV);

    //        IPColorChannels colorChannels = new IPColorChannels("Example2", MyStrings.channelsNames);
    //        colorChannels.displayImageProccessed(image);
    //        
    //        List<Mat> hsvImageChannels;
    //        hsvImageChannels = new ArrayList<>();
    //        
    //        Core.split(imageHSV, hsvImageChannels);
    //        
    //        ImageProccessingFrameTabs hsvChannels = new IPColorChannels("Example2", MyStrings.channelsNames);
    //        Mat[] channels =  (Mat[]) hsvImageChannels.toArray();
    //        hsvChannels.displayImageProccessed(channels[0]);
}

From source file:video.PictureAnalyser.java

public Mat blur(Mat input, int numberOfTimes) {
    Mat sourceImage = new Mat();
    Mat destImage = input.clone();
    for (int i = 0; i < numberOfTimes; i++) {
        sourceImage = destImage.clone();
        Imgproc.blur(sourceImage, destImage, new Size(5.0, 5.0));
    }/* ww w. j  a  v  a2  s.  c  o m*/
    return destImage;
}