Example usage for org.opencv.core Mat height

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

Introduction

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

Prototype

public int height() 

Source Link

Usage

From source file:bgslibrary.Utils.java

License:Open Source License

static final public void imshow(Mat image) {
    try {/* w  w w.j ava  2s. com*/
        BufferedImage bufImage = toBufferedImage(image);
        JFrame frame = new JFrame("Image");
        frame.getContentPane().setLayout(new FlowLayout());
        frame.getContentPane().add(new JLabel(new ImageIcon(bufImage)));
        frame.pack();
        frame.setSize(image.width() + 40, image.height() + 60);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:br.cefetmg.lsi.opencv.multipleObjectTracking.processing.MultipleObjectTracking.java

License:Open Source License

private void setFramesSizes(Mat image) {
    frameCamera.setSize(image.width() + 20, image.height() + 60);

    if (calibrationMode) {
        frameThreshold.setSize(image.width() + 20, image.height() + 60);
    }// ww w  .  j  a va  2  s . c o m

}

From source file:by.zuyeu.deyestracker.core.detection.DemoPanel.java

/**
 * Converts/writes a Mat into a BufferedImage.
 *
 * @param matrix Mat of type CV_8UC3 or CV_8UC1
 * @return BufferedImage of type TYPE_3BYTE_BGR or TYPE_BYTE_GRAY
 *///  w  ww  . j  a va  2 s.  c o m
public boolean convertMatToBufferedImage(Mat matBGR) {

    int width = matBGR.width(), height = matBGR.height(), channels = matBGR.channels();
    byte[] sourcePixels = new byte[width * height * channels];
    matBGR.get(0, 0, sourcePixels);
    // create new image and get reference to backing data
    image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
    final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
    System.arraycopy(sourcePixels, 0, targetPixels, 0, sourcePixels.length);

    return true;
}

From source file:by.zuyeu.deyestracker.core.detection.DemoPanel.java

public static void main(String arg[]) throws DEyesTrackerException, InterruptedException, ExecutionException {
    LOG.info("main - start;");
    final String windowName = "Capture - Face detection";
    final JFrame frame = new JFrame(windowName);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(400, 400);//from  w  w w.j a  v  a2 s .co m
    final DemoPanel demoPanel = new DemoPanel();
    frame.setContentPane(demoPanel);
    frame.setVisible(true);

    //-- 2. Read the video stream
    final FaceInfoSampler sampler = new FaceInfoSampler();
    final IFrameCapture capture = sampler.getCapture();
    final Scalar faceRegionColor = new Scalar(0, 255, 0);
    final Scalar eyesRegionColor = new Scalar(120, 120, 120);

    final ExecutorService executorService = Executors.newSingleThreadExecutor();
    FutureTask<DetectFaceSample> detectFaceTask = TaskUtils.wrapFutureAnd(new DetectTask(sampler),
            executorService);
    DetectFaceSample sample = new DetectFaceSample();
    while (true) {
        final Mat webcamImage = capture.getNextFrame();
        if (webcamImage != null && !webcamImage.empty()) {
            frame.setSize(webcamImage.width() + 40, webcamImage.height() + 60);

            if (detectFaceTask.isDone()) {
                sample = detectFaceTask.get();

                detectFaceTask = TaskUtils.wrapFutureAnd(new DetectTask(sampler), executorService);
            }

            if (sample.getFace() != null) {
                addRectangleToImage(sample.getFace(), webcamImage, faceRegionColor);
            }
            if (sample.getLeftEye() != null) {
                addRectangleToImage(sample.getLeftEye(), webcamImage, eyesRegionColor);
            }
            if (sample.getRightEye() != null) {
                addRectangleToImage(sample.getRightEye(), webcamImage, eyesRegionColor);
            }
            if (sample.getLeftPupil() != null) {
                drawCircle(webcamImage, sample.getLeftPupil());
            }
            if (sample.getRightPupil() != null) {
                drawCircle(webcamImage, sample.getRightPupil());
            }

            //-- 4. Display the image
            demoPanel.convertMatToBufferedImage(webcamImage); // We could look at the error...
            demoPanel.repaint();
        }
    }
}

From source file:by.zuyeu.deyestracker.core.util.CVCoreUtils.java

public static Mat selectSubmatByRect(Rect rect, Mat image) {
    double colScale = 1.0 * image.cols() / image.width();
    int colStart = (int) (1.0 * rect.x * colScale);
    int colEnd = (int) (1.0 * (rect.x + rect.width) * colScale);
    double rowScale = 1.0 * image.rows() / image.height();
    int rowStart = (int) (1.0 * rect.y * rowScale);
    int rowEnd = (int) (1.0 * (rect.y + rect.height) * rowScale);

    return image.submat(rowStart, rowEnd, colStart, colEnd);
}

From source file:by.zuyeu.deyestracker.core.util.CVCoreUtils.java

public static void insertSubmatByRect(Mat subImage, Rect rect, Mat origImage) {
    double colScale = 1.0 * origImage.cols() / origImage.width();
    int colStart = (int) (1.0 * rect.x * colScale);
    double rowScale = 1.0 * origImage.rows() / origImage.height();
    int rowStart = (int) (1.0 * rect.y * rowScale);
    for (int x1 = 0, x2 = colStart; x1 < subImage.cols(); x1++, x2++) {
        for (int y1 = 0, y2 = rowStart; y1 < subImage.rows(); y1++, y2++) {
            final double[] subImgData = subImage.get(y1, x1);
            origImage.put(y2, x2, subImgData);
        }//from w  w  w.ja v a 2 s. com
    }
}

From source file:cctvanalization.FXMLDocumentController.java

private static void saveFrame(Mat currentFrame, String fileName, String ext) {
    File file = new File(fileName + "." + ext);
    BufferedImage image = new BufferedImage(currentFrame.width(), currentFrame.height(),
            BufferedImage.TYPE_BYTE_GRAY);
    try {// w w w  . ja v  a  2 s  . com
        ImageIO.write(image, ext, file); // ignore returned boolean
    } catch (IOException e) {
        System.out.println("Write error for " + file.getPath() + ": " + e.getMessage());
    }
}

From source file:Clases.Analizador.java

public BufferedImage analizarMelanoma(Mat img) {
    int totalP, areaM, tamImg = img.width() * img.height();
    Mat imagenCopia = img.clone();/*from   w ww  . j  a  va 2 s.  c  o  m*/
    Mat imagenCopia1 = img.clone();
    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:classes.TextExtractor.java

public void extractText(Rect roi, double roiAngle) throws Exception {

    Point roiTopLeft = roi.tl();//ww w.j a  v a 2  s.co  m

    double radians = Math.toRadians(roiAngle);
    double sin = Math.abs(Math.sin(radians));
    double cos = Math.abs(Math.cos(radians));

    int newWidth = (int) (image.width() * cos + image.height() * sin);
    int newHeight = (int) (image.width() * sin + image.height() * cos);

    int[] newWidthHeight = { newWidth, newHeight };

    int pivotX = newWidthHeight[0] / 2;
    int pivotY = newWidthHeight[1] / 2;

    Point center = new Point(pivotX, pivotY);

    Size targetSize = new Size(newWidthHeight[0], newWidthHeight[1]);

    Mat intermediateImage = new Mat(targetSize, image.type());

    int offsetX = (newWidthHeight[0] - image.width()) / 2;
    int offsetY = (newWidthHeight[1] - image.height()) / 2;

    Point paddedTopLeft = new Point(roiTopLeft.x + offsetX, roiTopLeft.y + offsetY);

    Mat containerImage = intermediateImage.submat(offsetY, offsetY + image.height(), offsetX,
            offsetX + image.width());
    image.copyTo(containerImage);

    Mat rotationMatrix = Imgproc.getRotationMatrix2D(center, roiAngle, 1.0);

    Point transformedTopLeft = transformPoint(paddedTopLeft, rotationMatrix);

    Mat rotatedImage = new Mat();
    Imgproc.warpAffine(intermediateImage, rotatedImage, rotationMatrix, targetSize, Imgproc.INTER_LINEAR,
            Imgproc.BORDER_CONSTANT, new Scalar(0));

    ImageUtils.saveImage(rotatedImage, imageID + "_rotatedImage.png", request);

    double adjustedWidth = roi.size().width;
    double adjustedHeight = roi.size().height;

    if (transformedTopLeft.x + adjustedWidth > rotatedImage.width()) {
        adjustedWidth = rotatedImage.width() - transformedTopLeft.x;
    }

    if (transformedTopLeft.y + adjustedHeight > rotatedImage.height()) {
        adjustedHeight = rotatedImage.height() - transformedTopLeft.y;
    }

    Rect newROI = new Rect(transformedTopLeft, new Size(adjustedWidth, adjustedHeight));

    Mat extractedROI = new Mat(rotatedImage, newROI);

    String fileName = ImageUtils.saveImage(extractedROI, imageID + "_ROI.png", request);

    extractText(fileName);
}

From source file:classes.Util.java

public static BufferedImage mat2Img(Mat in) {
    BufferedImage out;/*from www  . j  a v a 2s. co  m*/
    byte[] data = new byte[in.width() * in.height() * (int) in.elemSize()];
    int type;
    in.get(0, 0, data);

    if (in.channels() == 1) {
        type = BufferedImage.TYPE_BYTE_GRAY;
    } else {
        type = BufferedImage.TYPE_3BYTE_BGR;
    }

    out = new BufferedImage(in.width(), in.height(), type);

    out.getRaster().setDataElements(0, 0, in.width(), in.height(), data);
    return out;
}