How to capture webcam images in OpenCV in Java?

1
Hello, I'm a beginner in opencv with java, and my problem is this, I want to capture the real-time image from my webcam and transmit it in a JLabel, however I'm having a problem executing the file, netbeans points the following error:

  

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: org.opencv.core.Mat.n_Mat () J

I'm using the VideoCapture function from the opencv library, below the code snippet:

private void BotaoStartActionPerformed(java.awt.event.ActionEvent evt){                                           
    Mat imageMat = new Mat(); // matriz de imagem //

    VideoCapture capture = new VideoCapture();
    capture.open(0); // abre dispositivo de video de índice 0 //

    // especifica altura e largura do video //
    capture.set(org.opencv.highgui.Highgui.CV_CAP_PROP_FRAME_HEIGHT, 320);
    capture.set(org.opencv.highgui.Highgui.CV_CAP_PROP_FRAME_WIDTH, 640);

    BufferedImage image;

    capture.read(imageMat); //Captura o quadro
    image = this.matToBufferedImage(imageMat); //Converte para imageBuffer

    while(capture.isOpened()){
        Icon icon = new ImageIcon(image);
        this.TelaImagem.setIcon(icon);
        this.TelaImagem.repaint();

        try {
            Thread.sleep(150);
        } catch (InterruptedException ex) {

        }
    }

}                         

This is the function that converts the type Mat to BufferedImage:

public BufferedImage matToBufferedImage(Mat matrix) {  
 int cols = matrix.cols();  
 int rows = matrix.rows();  
 int elemSize = (int)matrix.elemSize();  
 byte[] data = new byte[cols * rows * elemSize];  
 int type;  
 matrix.get(0, 0, data);  
 switch (matrix.channels()) {  
   case 1:  
     type = BufferedImage.TYPE_BYTE_GRAY;  
     break;  
   case 3:  
     type = BufferedImage.TYPE_3BYTE_BGR;  
     // bgr to rgb  
     byte b;  
     for(int i=0; i<data.length; i=i+3) {  
       b = data[i];  
       data[i] = data[i+2];  
       data[i+2] = b;  
     }  
     break;  
   default:  
     return null;  
 }  
 BufferedImage image = new BufferedImage(cols, rows, type);  
 image.getRaster().setDataElements(0, 0, cols, rows, data);  
 return image;  

}

the error points to the declaration line of Mat imageMat = new Mat (); , would anyone know what is causing this error? Thank you in advance.

    
asked by anonymous 07.03.2016 / 03:00

0 answers