Example usage for org.opencv.core Mat copyTo

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

Introduction

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

Prototype

public void copyTo(Mat m) 

Source Link

Usage

From source file:org.akvo.caddisfly.sensor.colorimetry.strip.util.ResultUtil.java

License:Open Source License

@NonNull
public static Mat concatenateHorizontal(@NonNull Mat m1, @NonNull Mat m2) {
    int width = m1.cols() + m2.cols() + HORIZONTAL_MARGIN;
    int height = Math.max(m1.rows(), m2.rows());

    Mat result = new Mat(height, width, CvType.CV_8UC3,
            new Scalar(MAX_RGB_INT_VALUE, MAX_RGB_INT_VALUE, MAX_RGB_INT_VALUE));

    // rect works with x, y, width, height
    Rect roi1 = new Rect(0, 0, m1.cols(), m1.rows());
    Mat roiMat1 = result.submat(roi1);//from  w w  w. j  av a  2 s  .  c  o m
    m1.copyTo(roiMat1);

    Rect roi2 = new Rect(m1.cols() + HORIZONTAL_MARGIN, 0, m2.cols(), m2.rows());
    Mat roiMat2 = result.submat(roi2);
    m2.copyTo(roiMat2);

    return result;
}

From source file:org.openpnp.machine.reference.ReferenceCamera.java

License:Open Source License

private Mat crop(Mat mat) {
    if (cropWidth != 0 || cropHeight != 0) {
        Rect roi = new Rect((int) ((mat.size().width / 2) - (cropWidth / 2)),
                (int) ((mat.size().height / 2) - (cropHeight / 2)), cropWidth, cropHeight);
        Mat tmp = new Mat(mat, roi);
        tmp.copyTo(mat);
        tmp.release();//  ww w .  j av  a  2 s . c  o  m
    }
    return mat;
}

From source file:org.usfirst.frc.team2084.CMonster2016.vision.CameraCalibration.java

License:Open Source License

/**
 * Draws checkerboard corners on an image.
 * /*w  w w . j a  v  a 2s  . com*/
 * @param image the image to process
 * @param addToCalibration if true, add this image to the corner list
 */
public void process(Mat image, boolean addToCalibration) {
    boolean patternFound = Calib3d.findChessboardCorners(image, boardSize, boardCorners,
            Calib3d.CALIB_CB_ADAPTIVE_THRESH | Calib3d.CALIB_CB_NORMALIZE_IMAGE | Calib3d.CALIB_CB_FAST_CHECK);

    if (patternFound) {
        // Refine corner positions to be more accurate
        Imgproc.cvtColor(image, grayImage, Imgproc.COLOR_BGR2GRAY);
        Imgproc.cornerSubPix(grayImage, boardCorners, new Size(6, 6), new Size(-1, -1),
                new TermCriteria(TermCriteria.EPS + TermCriteria.COUNT, 30, 0.1));

        if (addToCalibration) {
            calibrationCorners.add(boardCorners);
        }

    }

    image.copyTo(boardImage);
    Calib3d.drawChessboardCorners(boardImage, boardSize, boardCorners, patternFound);

    if (!addToCalibration) {
        debugImage("Board", boardImage);
    }

    Imgproc.undistort(image, undistortImage, cameraMatrix, distCoeffs);

    undistortImage.copyTo(image);

    Imgproc.putText(image, "Error: " + error, new Point(20, 20), Core.FONT_HERSHEY_PLAIN, 1.5,
            new Scalar(0, 255, 0));
}

From source file:org.usfirst.frc.team2084.CMonster2016.vision.HighGoalProcessor.java

License:Open Source License

private List<MatOfPoint> findContours(Mat image) {
    Mat hierarchy = new Mat();
    ArrayList<MatOfPoint> contours = new ArrayList<>();
    image.copyTo(contoursImage);
    Imgproc.findContours(contoursImage, contours, hierarchy, Imgproc.RETR_EXTERNAL,
            Imgproc.CHAIN_APPROX_SIMPLE);
    return contours;
}

From source file:org.usfirst.frc.team2084.CMonster2016.vision.ThreadedVisionProcessor.java

License:Open Source License

/**
 * @param image/* w w  w.j a  v  a2 s  .  c o  m*/
 */
@Override
public final void process(Mat image) {
    preProcess(image);

    if (runInBackground) {
        // Copy the image for the processing thread
        synchronized (this.image) {
            image.copyTo(this.image);
            newImage = true;
            this.image.notify();
        }
    } else {
        backgroundProcess(image);
    }

    postProcess(image);
}

From source file:rfea.ProcesarImagen.java

public void DetectarRostro() {
    System.out.println("\nDetectando rostros");

    // Create a face detector from the cascade file in the resources
    // directory.

    // System.out.println(rutaDe("/recursos/haarcascade_frontalface_alt.xml"));
    CascadeClassifier faceDetector = new CascadeClassifier(rutaDe("/recursos/haarcascade_frontalface_alt.xml"));

    //// ww  w.j a  va  2s .  c  om

    image = Highgui.imread(imagenEntrada);
    Mat temp = new Mat();
    Imgproc.cvtColor(image, temp, Imgproc.COLOR_BGRA2GRAY, 0);
    Mat temp_rgba = new Mat();
    Imgproc.cvtColor(temp, temp_rgba, Imgproc.COLOR_GRAY2BGRA, 0);
    temp_rgba.copyTo(image);
    temp.copyTo(image);
    equalizeHist(image, image);

    tmp = image;
    //    

    // Detect faces in the image.
    // MatOfRect is a special container class for Rect.
    MatOfRect faceDetections = new MatOfRect();
    faceDetector.detectMultiScale(image, faceDetections);
    contRostros = faceDetections.toArray().length;
    if (contRostros < 1) {
        System.out
                .println("No se an detectado rostros, profavor acerquese a la camara en una posicion adecuada");
        return;
    } else if (contRostros > 1) {
        System.out.println("se dectactaron mas de 1 rostros, seleecione 1 para evaluar");
        for (int i = 0; i < faceDetections.toArray().length; i++) {

            roiRostro = faceDetections.toArray()[i];
            Core.rectangle(image, new Point(roiRostro.x, roiRostro.y),
                    new Point(roiRostro.x + roiRostro.width, roiRostro.y + roiRostro.height),
                    new Scalar(0, 255, 0));
        }
        Principal.setRostro(image);
        new SeleccionImg().setVisible(true);

    } else {

        System.out.println(String.format("%s rostro Detectado, en la iteracion: " + cont,
                faceDetections.toArray().length));

        // Draw a bounding box around each face.
        //for (Rect roiRostro : faceDetections.toArray()) {
        for (int i = 0; i < faceDetections.toArray().length; i++) {

            roiRostro = faceDetections.toArray()[i];
            Core.rectangle(image, new Point(roiRostro.x, roiRostro.y),
                    new Point(roiRostro.x + roiRostro.width, roiRostro.y + roiRostro.height),
                    new Scalar(0, 255, 0));
        }

        // Save the visualized detection.
        String filename = imagenSalida;
        System.out.println(String.format("Guardado %s", filename));
        Highgui.imwrite(filename, image);
        recortarRostro();
        this.detectarOjos();
        this.detectarNariz();
        detectarBoca();
    }

}

From source file:samples.FtcTestOpenCv.java

License:Open Source License

/**
 * This method rotate the image to the specified angle.
 *
 * @param src specifies the image to be rotated.
 * @param dst specifies the destination to put the rotated image.
 * @param angle specifies the rotation angle.
 *//*from ww  w .ja  v a 2s .  c  o m*/
private void rotateImage(Mat src, Mat dst, double angle) {
    angle %= 360.0;
    if (angle == 0.0) {
        src.copyTo(dst);
    } else if (angle == 90.0 || angle == -270.0) {
        Core.transpose(src, dst);
        Core.flip(dst, dst, 1);
    } else if (angle == 180.0 || angle == -180.0) {
        Core.flip(src, dst, -1);
    } else if (angle == 270.0 || angle == -90.0) {
        Core.transpose(src, dst);
        Core.flip(dst, dst, 0);
    } else {
        Mat rotMat = Imgproc.getRotationMatrix2D(new Point(src.cols() / 2.0, src.rows() / 2.0), angle, 1.0);
        Imgproc.warpAffine(src, dst, rotMat, src.size());
    }
}

From source file:src.main.java.org.roomwatcher.watcher.Processor.java

public Mat detect(Mat inputframe) {
    Mat mRgba = new Mat();
    Mat mGrey = new Mat();
    MatOfRect faces = new MatOfRect();

    inputframe.copyTo(mRgba);
    inputframe.copyTo(mGrey);//from   w w w.  j a  va2 s .  c om

    Imgproc.cvtColor(mRgba, mGrey, Imgproc.COLOR_BGR2GRAY);
    Imgproc.equalizeHist(mGrey, mGrey);

    face_cascade.detectMultiScale(mGrey, faces);
    Window.setPeopleNumberLabelValue(String.valueOf(faces.toArray().length));

    for (Rect rect : faces.toArray()) {
        Point center = new Point(rect.x + rect.width * 0.5, rect.y + rect.height * 0.5);
        Core.ellipse(mRgba, center, new Size(rect.width * 0.5, rect.height * 0.5), 0, 0, 360,
                new Scalar(255, 0, 255), 4, 8, 0);
    }

    return mRgba;
}

From source file:tk.year.opencv.demo.commons.FilteringImageProvider.java

License:Open Source License

@Override
public Mat get() {

    final Mat img = imgProvider.get();
    Mat dst = new Mat();
    img.copyTo(dst);
    for (final ImageFilters.Entry entry : imageFiltersProvider.get()) {
        if (entry.isEnabled() && entry.getFilter().isApplicable()) {
            try {
                dst = entry.getFilter().filter(dst);
            } catch (final Exception ex) {
                logger.error("Unable to apply filter: {}", entry.getFilter(), ex);
                return dst;
            }/*from   w  w  w .  j  a v  a 2  s .  co  m*/
        }
    }

    return dst;
}

From source file:tk.year.opencv.demo.filters.Dilate.java

License:Open Source License

@Override
public Mat filter(final Mat src) {

    final Mat dst = new Mat(src.cols(), src.rows(), CvType.CV_8UC3);
    src.copyTo(dst);

    Imgproc.dilate(dst, dst, structuringElement);

    return dst;/*from w ww .  j  ava  2s  .c  om*/
}