Utilisation de la caméra de l'ordinateur portable avec swing en java [fermé]


Comment utiliser la caméra en utilisant swing en java avec le système d'exploitation ubuntu veuillez me donner quelques exemples et directives pour utiliser la caméra via java.

public static void main(String[] args) {
    CamDemo t = new CamDemo();
    t.getCam();
}

public void getCam() {
    try {

        /* Grab the default web cam */
        MediaLocator ml = new MediaLocator("vfw://0");
        DataSource ds = Manager.createDataSource(ml);
        requestFormatResolution(ds);
        Player p = Manager.createRealizedPlayer(ds);
        p.start();
        Thread.currentThread().sleep(1000);
        JFrame jfrm = new JFrame("Testing Webcam");
        jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        if (p.getVisualComponent() != null)
            jfrm.getContentPane().add(p.getVisualComponent());
        if (p.getControlPanelComponent() != null)
            jfrm.getContentPane().add(p.getControlPanelComponent(),
                    BorderLayout.SOUTH);
        jfrm.pack();
        jfrm.setLocationRelativeTo(null);
        jfrm.setVisible(true);
        jfrm.setSize(320, 240);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

public boolean requestFormatResolution(DataSource ds) {

    if (ds instanceof CaptureDevice) {
        FormatControl[] fcs = ((CaptureDevice) ds).getFormatControls();
        for (FormatControl fc : fcs) {
            Format[] formats = ((FormatControl) fc).getSupportedFormats();
            for (Format format : formats) {
                if ((format instanceof VideoFormat)
                        && (((VideoFormat) format).getSize().getHeight() <= 240)
                        && (((VideoFormat) format).getSize().getWidth() <= 320)) {
                    ((FormatControl) fc).setFormat(format);
                    return true;
                }
            }
        }
    }
    return false;
}
}

Stacktrace:

javax.media.NoDataSourceException: Cannot find a DataSource for: vfw://0
at javax.media.Manager.createDataSource(Manager.java:1037)
at com.convoy.gpack.pack.CamDemo.getCam(CamDemo.java:32)
at com.convoy.gpack.pack.CamDemo.main(CamDemo.java:16)
Author: Philipp Sander, 2014-08-07

2 answers

Utilisation du projet Webcam Capture.

Exemple de l'auteur pour l'utilisation de l'API:

Webcam buildin = Webcam.getWebcams().get(0); // build-in laptop camera
Webcam usb = Webcam.getWebcams().get(1); // usb camera
BufferedImage image1 = buildin.getImage();
BufferedImage image2 = usb.getImage(); // do with image1 and image2 whatever you want
 4
Author: InterruptedException, 2014-08-07 13:42:20

Le Java Media Framework (jmf) est ce que vous cherchez.

 4
Author: Philipp Sander, 2014-08-07 13:39:42