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:video.PictureView.java

public static BufferedImage mat2Img(Mat in) {
    BufferedImage out;/*  w ww .  j  a v  a 2s .  c  o m*/
    int width = in.cols();
    int height = in.height();
    byte[] data = new byte[width * 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(width, height, type);

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

From source file:webcamcapture.WebCamCapture.java

/**
 * @param args the command line arguments
 *//*from w w  w .j a  v  a 2  s.  co  m*/
public static void main(String[] args) throws IOException {
    // TODO code application logic here

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    httpRequestSend request = new httpRequestSend();
    VideoCapture camera = new VideoCapture(0);
    int x = 0;
    if (!camera.isOpened()) {
        System.out.println("Error");
    } else {
        Mat frame = new Mat();
        while (true) {
            if (camera.read(frame)) {
                System.out.println("Frame Obtained");
                System.out.println("Captured Frame Width " + frame.width() + " Height " + frame.height());
                Highgui.imwrite("camera" + x + ".jpg", frame);
                //System.out.println("OK");
                // break;

                request.request("https://fireacc.herokuapp.com/dash", "camera" + x + ".jpg");
                x++;
            }
            try {
                //}
                Thread.sleep(5000);
            } catch (InterruptedException ex) {
                System.out.println("stuck");
            }
        }
    }
    camera.release();

}

From source file:webcamfacedetect.FaceDetect.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
 *//*from w  w  w  .j a v a2  s .c  o  m*/
public boolean MatToBufferedImage(Mat matBGR) {
    long startTime = System.nanoTime();
    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);
    long endTime = System.nanoTime();
    //System.out.println(String.format("Elapsed time: %.2f ms", (float) (endTime - startTime) / 1000000));
    return true;
}

From source file:webcamfacedetect.WebcamFaceDetect.java

/**
 * @param args the command line arguments
 *//*  w ww.j  av  a  2s .  c  o m*/
public static void main(String args[]) {
    // Load the native library.
    Libloader.load();
    String window_name = "Capture - Face detection";
    JFrame frame = new JFrame(window_name);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(1024, 800);
    FaceDetect faceDetect = new FaceDetect();
    Processor my_processor = new Processor();
    frame.setContentPane(faceDetect);
    frame.setVisible(true);
    // Read the video stream  
    Mat webcam_image = new Mat();
    VideoCapture capture = null;
    for (int numCam = 0; numCam < 5; numCam++) {
        try {
            capture = new VideoCapture(numCam);
            break;
        } catch (Exception e) {
            System.out.println("Webcam number " + numCam + " unavailable ...");
        }
    }
    if (capture.isOpened()) {
        while (true) {
            capture.read(webcam_image);
            if (!webcam_image.empty()) {
                frame.setSize(webcam_image.width() + 40, webcam_image.height() + 60);
                // Apply the classifier to the captured image  
                webcam_image = my_processor.detect(webcam_image);
                // Display recognized image  
                faceDetect.MatToBufferedImage(webcam_image);
                faceDetect.repaint();
            } else {
                System.out.println("No captured frame. Exit.");
                break;
            }
        }
    }
}