Capturar Video en Java

Capturar Video
13 de Marzo del 2010
hola, estoy haciendo un programa de vision artificial y necesito capturar el video que me proporciona una webCam. Si alguien m epuede ayudar por favor envienme paginas web que contengan esta informacion o decirme con que libreria trabajo. Si mas un pequeño ejemplo. Lo necesito urgentemente. Antetodo Gracias

Ya tengo un codigo pero esta en C, como lo paso para java

mamuso
13 de Marzo del 2010
Buenas, estoy haciendo lo mismo y te puedo decir que JMF es la solución, pero no encuentro mucho en castellano acerca del tema. Cuando tenga algo hecho postearé el código. Me estoy empapando los manuales en inglés y vaya rollazo... xD Si veis algún tutorial en español sencillito ( capturar el video y muestrear imágenes fijas del mismo principalmente ) postead la dirección ¡Por caridad! ;)

ana
13 de Marzo del 2010
hola , yo tambien estoy trabajando en lo mismo y en la pagina de sun hay y este codigo tambien os puede servir,


HACEMOS UNA CAPTURA DE LA ENTRADA DE VIDEO DE UNA WEBCAM, Y LO REPRODUCIMOS POR PANTALLA

TODO ELLO MEDIANTE:


1º/ CONFIGURAMOS EL DISPOSITIVO DE CAPTURA DE VIDEO , EN ESTE CASO , CAMARAWEB, MEDIANTE
JFMREGISTRI, EN
After you run JMFRegistry from the command line or inside your Java tool
Click the "Capture Devices" tab, and then click the "Detect Capture Devices" button.
A list should display all the audio and video capture devices on the system.
As seen in Figure 1, JMFRegistry found JavaSound audio capture,
a Logitech USB Video Camera, and Microsoft WDM Image Capture.
Clicking a list item will display all formats that can be used for that capture device.
For example, the Logitech USB camera in Figure 1 supports RGB color with a resolution
of 352x288, 160x120, and so on.

2º/COMPILADO LOS ARCHIVOS CAPTUREDEVICEDIALOG.JAVA Y JMF.JAVA SE EJECUTA JMF.JAVA Y YA RECONOCE
LOS DISPOSITIVOS DE AUDIO Y VIDEO, EN CONFIGURE,Y EN ACTION LE DAMOS A CAPTURE, Y CAPTURA Y
REPRODUCE.
Aqui teneis el codigo suerte
//package JMF;
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.media.*;
import javax.media.format.*;
import javax.media.protocol.DataSource;

public class CaptureDeviceDialog extends Dialog implements ActionListener, ItemListener {

boolean configurationChanged = false;
Vector devices;
Vector audioDevices;
Vector videoDevices;
Vector audioFormats;
Vector videoFormats;
Choice audioDeviceCombo;
Choice videoDeviceCombo;
Choice audioFormatCombo;
Choice videoFormatCombo;


public CaptureDeviceDialog(Frame parent, String title, boolean mode) {
super(parent, title, mode);
init();
}

private void init() {
setSize(450, 180);
Panel p = new Panel();
p.setLayout(null);

Label l1 = new Label("Audio Device(s)");
Label l2 = new Label("Video Device(s)");
Label l3 = new Label("Audio Format(s)");
Label l4 = new Label("Video Format(s)");
audioDeviceCombo = new Choice();
videoDeviceCombo = new Choice();
audioFormatCombo = new Choice();
videoFormatCombo = new Choice();

Button OKbutton = new Button("OK");
Button cancelButton = new Button("Cancel");


p.add(l1);
l1.setBounds(5, 5, 100, 20);
p.add(audioDeviceCombo);
audioDeviceCombo.setBounds(115, 5, 300, 20);
p.add(l3);
l3.setBounds(5, 30, 100,20);
p.add(audioFormatCombo);
audioFormatCombo.setBounds(115, 30, 300,20);
p.add(l2);
l2.setBounds(5, 55, 100, 20);
p.add(videoDeviceCombo);
videoDeviceCombo.setBounds(115, 55, 300, 20);
p.add(l4);
l4.setBounds(5, 80, 100, 20);
p.add(videoFormatCombo);
videoFormatCombo.setBounds(115, 80, 300, 20);
p.add(OKbutton);
OKbutton.setBounds(280, 115, 60, 25);
p.add(cancelButton);
cancelButton.setBounds(355, 115, 60, 25);

add(p, "Center");
audioDeviceCombo.addItemListener(this);
videoDeviceCombo.addItemListener(this);
OKbutton.addActionListener(this);
cancelButton.addActionListener(this);

//get all the capture devices
devices = CaptureDeviceManager.getDeviceList ( null );
CaptureDeviceInfo cdi;
if (devices!=null && devices.size()>0) {
int deviceCount = devices.size();
audioDevices = new Vector();
videoDevices = new Vector();

Format[] formats;
for ( int i = 0; i < deviceCount; i++ ) {
cdi = (CaptureDeviceInfo) devices.elementAt ( i );
formats = cdi.getFormats();
for ( int j=0; j<formats.length; j++ ) {
if ( formats[j] instanceof AudioFormat ) {
audioDevices.addElement(cdi);
break;
}
else if (formats[j] instanceof VideoFormat ) {
videoDevices.addElement(cdi);
break;
}
}
}

//populate the choices for audio
for (int i=0; i<audioDevices.size(); i++) {
cdi = (CaptureDeviceInfo) audioDevices.elementAt(i);
audioDeviceCombo.addItem(cdi.getName());
}

//populate the choices for video
for (int i=0; i<videoDevices.size(); i++) {
cdi = (CaptureDeviceInfo) videoDevices.elementAt(i);
videoDeviceCombo.addItem(cdi.getName());
}

displayAudioFormats();
displayVideoFormats();

} // end if devices!=null && devices.size>0
else {
//no devices found or something bad happened.
}
}

void displayAudioFormats() {
//get audio formats of the selected audio device and repopulate the audio format combo
CaptureDeviceInfo cdi;
audioFormatCombo.removeAll();

int i = audioDeviceCombo.getSelectedIndex();
//i = -1 --> no selected index

if (i!=-1) {
cdi = (CaptureDeviceInfo) audioDevices.elementAt(i);
if (cdi!=null) {
Format[] formats = cdi.getFormats();
audioFormats = new Vector();
for (int j=0; j<formats.length; j++) {
audioFormatCombo.add(formats[j].toString());
audioFormats.addElement(formats[j]);
}
}
}
}

void displayVideoFormats() {
//get audio formats of the selected audio device and repopulate the audio format combo
CaptureDeviceInfo cdi;
videoFormatCombo.removeAll();

int i = videoDeviceCombo.getSelectedIndex();
//i = -1 --> no selected index

if (i!=-1) {
cdi = (CaptureDeviceInfo) videoDevices.elementAt(i);
if (cdi!=null) {
Format[] formats = cdi.getFormats();
videoFormats = new Vector();
for (int j=0; j<formats.length; j++) {
videoFormatCombo.add(formats[j].toString());
videoFormats.addElement(formats[j]);
}
}
}
}

public CaptureDeviceInfo getAudioDevice() {
CaptureDeviceInfo cdi = null;
if (audioDeviceCombo!=null) {
int i = audioDeviceCombo.getSelectedIndex();
cdi = (CaptureDeviceInfo) audioDevices.elementAt(i);
}
return cdi;
}

public CaptureDeviceInfo getVideoDevice() {
CaptureDeviceInfo cdi = null;
if (videoDeviceCombo!=null) {
int i = videoDeviceCombo.getSelectedIndex();
cdi = (CaptureDeviceInfo) videoDevices.elementAt(i);
}
return cdi;
}

public Format getAudioFormat() {
Format format = null;
if (audioFormatCombo!=null) {
int i = audioFormatCombo.getSelectedIndex();
format = (Format) audioFormats.elementAt(i);
}
return format;
}

public Format getVideoFormat() {
Format format = null;
if (videoFormatCombo!=null) {
int i = videoFormatCombo.getSelectedIndex();
format = (Format) videoFormats.elementAt(i);
}
return format;
}

public boolean hasConfigurationChanged() {
return configurationChanged;
}

public void actionPerformed(ActionEvent ae) {
String command = ae.getActionCommand().toString();
if (command.equals("OK")) {
configurationChanged = true;
}
dispose();
}

public void itemStateChanged(ItemEvent ie) {
System.out.println(ie.getSource().toString());
if (ie.getSource().equals(audioDeviceCombo))
displayAudioFormats();
else
displayVideoFormats();

}
}


funciona de verdad