Example usage for org.opencv.core Mat size

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

Introduction

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

Prototype

public Size size() 

Source Link

Usage

From source file:com.shootoff.camera.autocalibration.AutoCalibrationManager.java

License:Open Source License

private Point findChessBoardSquareCenter(Mat corners, int row, int col) {
    if (row >= PATTERN_HEIGHT - 1 || col >= PATTERN_WIDTH - 1) {
        logger.warn("findChessBoardSquareColor invalid row or col {} {}", row, col);
        return null;
    }/*from  w  w  w.  j  ava 2s.  c om*/

    final Point topLeft = new Point(corners.get((row * PATTERN_WIDTH - 1) + col, 0)[0],
            corners.get((row * PATTERN_WIDTH - 1) + col, 0)[1]);
    final Point bottomRight = new Point(corners.get(((row + 1) * PATTERN_WIDTH - 1) + col + 1, 0)[0],
            corners.get(((row + 1) * PATTERN_WIDTH - 1) + col + 1, 0)[1]);

    final Point result = new Point((topLeft.x + bottomRight.x) / 2, (topLeft.y + bottomRight.y) / 2);

    if (logger.isTraceEnabled()) {
        logger.trace("findChessBoardSquareColor {}", corners.size());

        logger.trace("findChessBoardSquareColor {} {}", (row * PATTERN_WIDTH - 1) + col,
                ((row + 1) * PATTERN_WIDTH - 1) + col + 1);
        logger.trace("findChessBoardSquareColor {} {} {}", topLeft, bottomRight, result);
    }

    return result;
}

From source file:com.sikulix.core.Finder.java

License:Open Source License

private Mat doFindMatch(Element target, Mat base, Mat probe) {
    if (SX.isNull(probe)) {
        probe = target.getContent();/*from  w ww  . j a va 2s .c  o  m*/
    }
    Mat result = new Mat();
    Mat plainBase = base;
    Mat plainProbe = probe;
    if (!target.isPlainColor()) {
        Imgproc.matchTemplate(base, probe, result, Imgproc.TM_CCOEFF_NORMED);
    } else {
        if (target.isBlack()) {
            Core.bitwise_not(base, plainBase);
            Core.bitwise_not(probe, plainProbe);
        }
        Imgproc.matchTemplate(plainBase, plainProbe, result, Imgproc.TM_SQDIFF_NORMED);
        Core.subtract(Mat.ones(result.size(), CvType.CV_32F), result, result);
    }
    return result;
}

From source file:com.superbool.easylpr.model.Transformation.java

public Mat crop(Size outputImageSize, Mat transformationMatrix) {

    Mat deskewed = new Mat(outputImageSize, this.bigImage.type());

    // Apply perspective transformation to the image
    Imgproc.warpPerspective(this.bigImage, deskewed, transformationMatrix, deskewed.size(),
            Imgproc.INTER_CUBIC);/*from w w w . jav a  2s  .  co m*/

    return deskewed;
}

From source file:com.wallerlab.compcellscope.MultiModeViewActivity.java

License:BSD License

public Mat generateMMFrame(Mat gridOut, Mat MatTL, Mat MatTR, Mat MatBL, Mat MatBR) {
    //gridOut = new Mat(100, 100, gridOut.type(), new Scalar(0,0,0));
    Mat Mat1 = new Mat(MatTL.size(), MatTL.type());
    Mat Mat2 = new Mat(MatTR.size(), MatTR.type());
    Mat Mat3 = new Mat(MatBL.size(), MatBL.type());
    Mat Mat4 = new Mat(MatBR.size(), MatBR.type());

    // Ensure all of the mats are of the correct size since pyramid operation resizes
    Imgproc.resize(MatTL, MatTL, sz);//  ww w .ja va  2 s.co  m
    Imgproc.resize(MatTR, MatTR, sz);
    Imgproc.resize(MatBL, MatBL, sz);
    Imgproc.resize(MatBR, MatBR, sz);

    // Downsample by 2 for 2x2 grid
    Imgproc.pyrDown(MatBL, Mat1);
    Imgproc.pyrDown(MatBR, Mat2);
    Imgproc.pyrDown(MatTL, Mat3);
    Imgproc.pyrDown(MatTR, Mat4);

    /*
    Log.d(TAG,String.format("TLRect format is %.1f-%.1f",TLRect.size().width,TLRect.size().height));
    Log.d(TAG,String.format("TRRect format is %.1f-%.1f",TRRect.size().width,TRRect.size().height));
            
    Log.d(TAG,String.format("BLRect format is %.1f-%.1f",BLRect.size().width,BLRect.size().height));
    Log.d(TAG,String.format("BRRect format is %.1f-%.1f",BRRect.size().width,BRRect.size().height));
            
    Log.d(TAG,String.format("MatTL format is %.1f-%.1f",MatTL.size().width,MatTL.size().height));
    Log.d(TAG,String.format("MatTR format is %.1f-%.1f",MatTR.size().width,MatTR.size().height));
            
    Log.d(TAG,String.format("MatBL format is %.1f-%.1f",MatBL.size().width,MatBL.size().height));
    Log.d(TAG,String.format("MatBR format is %.1f-%.1f",MatBR.size().width,MatBR.size().height));
     */

    Core.putText(Mat1, "DPC-LR", new Point(43, 40), Core.FONT_ITALIC, 1, new Scalar(255, 255, 0));
    Core.putText(Mat2, "DPC-TB", new Point(43, 40), Core.FONT_ITALIC, 1, new Scalar(255, 255, 0));
    Core.putText(Mat3, "BrightField", new Point(33, 40), Core.FONT_ITALIC, 1, new Scalar(255, 255, 0));
    Core.putText(Mat4, "DarkField", new Point(37, 40), Core.FONT_ITALIC, 1, new Scalar(255, 255, 0));

    Mat1.copyTo(gridOut.submat(BLRect));
    Mat2.copyTo(gridOut.submat(BRRect));
    Mat3.copyTo(gridOut.submat(TLRect));
    Mat4.copyTo(gridOut.submat(TRRect));

    Mat1.release();
    Mat2.release();
    Mat3.release();
    Mat4.release();

    return gridOut;
}

From source file:cpsd.ImageGUI.java

private void zoomImage(double zoomlevel) {
    Mat source = ImageClass.getInstance().getImage();
    Mat destination = new Mat((int) (source.rows() * zoomlevel), (int) (source.cols() * zoomlevel),
            source.type());/* ww w .j a  v  a2  s  . c o m*/
    Imgproc.resize(source, destination, destination.size(), zoomlevel, zoomlevel, INTER_CUBIC);
    ImageClass.getInstance().setImage(destination);
    zoomSlider.setValue((int) (zoomlevel * 10));
}

From source file:cpsd.ImageGUI.java

private void blurImage() {
    Mat source = ImageClass.getInstance().getImage();
    Mat destination = new Mat(source.size(), source.type());
    Imgproc.GaussianBlur(source, destination, new org.opencv.core.Size(0, 0), 2);
    // Imgproc.bilateralFilter(source, destination, , sensorSize, sensorSize, WIDTH);
    ImageClass.getInstance().setImage(destination);
}

From source file:ctPrincipal.Ruidos.java

private String ruidoGaussiano(int mean, int desv) {
    Mat original_Bgr = image.clone();
    Mat mGaussian_noise = new Mat(original_Bgr.size(), original_Bgr.type());
    randn(mGaussian_noise, mean, desv);// w  w  w .  j  a v  a 2s  .c om
    for (int m = 0; m < original_Bgr.rows(); m++) {
        for (int n = 0; n < original_Bgr.cols(); n++) {
            double[] val = new double[3];
            for (int i = 0; i < original_Bgr.get(m, n).length; i++) {
                val[i] = original_Bgr.get(m, n)[i] + mGaussian_noise.get(m, n)[i];
            }
            original_Bgr.put(m, n, val);
        }
    }
    normalize(original_Bgr, original_Bgr, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC3);
    Imgcodecs.imwrite("OutputImg/gaussian.jpg", original_Bgr);
    return "OutputImg/gaussian.jpg";
}

From source file:ctPrincipal.Ruidos.java

private String ruidoSalPimenta(int min, int max) {
    Mat saltPepper_img = image.clone();
    Mat mSaltPepper_noise = new Mat(saltPepper_img.size(), saltPepper_img.type());
    randn(mSaltPepper_noise, 0, 255);/*  www . j  ava2 s.  com*/
    for (int m = 0; m < saltPepper_img.rows(); m++) {
        for (int n = 0; n < saltPepper_img.cols(); n++) {
            double[] val = new double[3];
            if (mSaltPepper_noise.get(m, n)[0] < min && mSaltPepper_noise.get(m, n)[1] < min
                    && mSaltPepper_noise.get(m, n)[2] < min) {
                for (int i = 0; i < saltPepper_img.get(m, n).length; i++) {
                    val[i] = 0;
                }
                saltPepper_img.put(m, n, val);
            }
            if (mSaltPepper_noise.get(m, n)[0] > max && mSaltPepper_noise.get(m, n)[1] > max
                    && mSaltPepper_noise.get(m, n)[2] > max) {
                for (int i = 0; i < saltPepper_img.get(m, n).length; i++) {
                    val[i] = 255;
                }
                saltPepper_img.put(m, n, val);
            }
        }
    }
    normalize(saltPepper_img, saltPepper_img, 0, 255, Core.NORM_MINMAX, CvType.CV_8UC3);
    Imgcodecs.imwrite("OutputImg/saltpepper.jpg", saltPepper_img);
    return "OutputImg/saltpepper.jpg";
}

From source file:cx.uni.jk.mms.iaip.mat.CrossMatListener.java

License:Open Source License

/**
 * do the transfer from source to this.target, using DCT or IDCT
 * /*from w w w. ja  v a  2  s  .  c  o  m*/
 * @param source
 */
private void transfer(MatModel source) {
    Mat matSource = source.getMat();
    Mat matTarget = new Mat(matSource.size(), MatModel.MAT_TYPE);
    if (this.inverse) {
        Core.idct(matSource, matTarget);
    } else {
        Core.dct(matSource, matTarget);
    }
    this.target.setMat(matTarget);
}

From source file:de.hu_berlin.informatik.spws2014.mapever.entzerrung.CornerDetector.java

License:Open Source License

/**
 * Guesses the most likly corners of a distorted map within an image.
 * Expects OpenCV to be initialized.//from   w ww .j a va  2s.  c  o  m
 * The results are already pretty good but could propably be improved
 * via tweaking the parameters or adding some additional line filtering
 * criteria(like them being kind of parallel for instance...)
 * 
 * @param gray_img A grayscale image in OpenCVs Mat format.
 * @return An array of propable corner points in the following form: {x0,y0,x1,y1,x2,y2,x3,y3} or null on error.
 **/
public static Point[] guess_corners(Mat gray_img) {
    Mat lines = new Mat();
    Imgproc.Canny(gray_img, gray_img, THRESHOLD0, THRESHOLD1, APERTURE_SIZE, false);
    Imgproc.HoughLinesP(gray_img, lines, RHO, THETA, HOUGH_THRESHOLD,
            Math.min(gray_img.cols(), gray_img.rows()) / MIN_LINE_LENGTH_FRACTION, MAX_LINE_GAP);

    double[][] edge_lines = filter_lines(lines, gray_img.size());

    Point[] ret_val = new Point[4];
    ret_val[0] = find_intercept_point(edge_lines[0], edge_lines[2]);
    ret_val[1] = find_intercept_point(edge_lines[0], edge_lines[3]);
    ret_val[2] = find_intercept_point(edge_lines[1], edge_lines[3]);
    ret_val[3] = find_intercept_point(edge_lines[1], edge_lines[2]);

    // do sanity checks and return null on invalid coordinates
    for (int i = 0; i < 4; i++) {
        // check if coordinates are outside image boundaries
        if (ret_val[i].x < 0 || ret_val[i].y < 0 || ret_val[i].x > gray_img.width()
                || ret_val[i].y > gray_img.height()) {
            return null;
        }

        // check if point equal to other point
        for (int j = i + 1; j < 4; j++) {
            if (ret_val[j].x == ret_val[i].x && ret_val[j].y == ret_val[i].y) {
                return null;
            }
        }
    }

    return ret_val;
}