Webcam com DSJ problema

7 respostas
J

A camera parece que vai iniciar, acende os LEDs, mas não dá para ver ela no JPanel.
alguem sabe pq, como resolver isso

public void inicializa(){

        DSFilterInfo[][] info = DSCapture.queryDevices() ;
        for(int i=0;i<info.length;i++)
        {
            for(int j=0;j<info[i].length;j++)
            {
                System.out.println("["+i+"]["+j+"]"+info[i][j]);
            }
        }


        //info[0][0].setPreferredFormat(14);
        //info[0][0].

  //      info[0][1].setPreferredFormat(14);
//        info[0][2].setPreferredFormat(14);


        cam1graph = new DSCapture(DSFiltergraph.RENDER_NATIVE, info[0][0],
                              false, DSFilterInfo.doNotRender(),null);
        cam1graph.setVisible(true);
        comp=cam1graph.asComponent();
  //cam1graph.activateDevice(info[0][0]);
      
comp.setVisible(true);
jPanel1.add(java.awt.BorderLayout.CENTER,comp);
cam1graph.play();
jPanel1.setVisible(true);
        //cam1graph.play();
}

7 Respostas

J
jeanricier:
[color=red]A CAMERA PARECE QUE VAI INICIAR ACENDE OS LEDS, MAIS NAO DA PRA VER ELA NO jpanel[/color] alguem sabe pq, como resolver isso
public void inicializa(){

        DSFilterInfo[][] info = DSCapture.queryDevices() ;
        for(int i=0;i<info.length;i++)
        {
            for(int j=0;j<info[i].length;j++)
            {
                System.out.println("["+i+"]["+j+"]"+info[i][j]);
            }
        }


        //info[0][0].setPreferredFormat(14);
        //info[0][0].

  //      info[0][1].setPreferredFormat(14);
//        info[0][2].setPreferredFormat(14);


        cam1graph = new DSCapture(DSFiltergraph.RENDER_NATIVE, info[0][0],
                              false, DSFilterInfo.doNotRender(),null);
        cam1graph.setVisible(true);
        comp=cam1graph.asComponent();
  //cam1graph.activateDevice(info[0][0]);
      
comp.setVisible(true);
jPanel1.add(java.awt.BorderLayout.CENTER,comp);
cam1graph.play();
jPanel1.setVisible(true);
        //cam1graph.play();
}
Na verdade a câmera inicializou, mas a superfície onde o vídeo está sendo pintado não está enquadrado no seu formulário. Use o método pack() posteriormente. Detalhe, o formulário precisa implementar uma interface( que não me lembro o nome agora ) para mapear as mensagens dos quadros que chegam. Dá uma olhada no exemplo SimpleCapture.java
J
[color=red]tentei usar pack(); mais nao deu certo ainda tem algum erro ?????????????????????[/color]
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ServerCam.java
 *
 * Created on 30/07/2010, 01:06:05
 */

package pacote;

import de.humatic.dsj.*;
import java.awt.Image;


/**
 *
 * @author Administrador
 */
public class ServerCam extends javax.swing.JFrame implements java.beans.PropertyChangeListener {
    private DSCapture graph;
public Image im=null;
 public Image img=null;

    /** Creates new form ServerCam */
    public ServerCam() {
    initComponents();
    Iniciacamera();
    }

        
      //  Iniciacamera();
        
        public void Iniciacamera(){


      // javax.swing.JFrame f = new javax.swing.JFrame("WebCam Servidor");

        DSFilterInfo[][] dsi = DSCapture.queryDevices();

        graph = new DSCapture(DSFiltergraph.RENDER_NATIVE, dsi[0][0], false, DSFilterInfo.doNotRender(),  this);
   //add(java.awt.BorderLayout.NORTH, graph.asComponent());

        jPanel1.add(java.awt.BorderLayout.CENTER, graph.asComponent());
        
        jPanel1.setVisible(true);
        graph.setVisible(true);
        graph.play();

  
pack();
this.pack();
              setSize(840,680);
        setVisible(true);
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);


       // f.add(java.awt.BorderLayout.NORTH, graph.asComponent());
       // f.setSize(840,680);
       // f.setVisible(true);


        //f.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);


//jPanel1.add(java.awt.BorderLayout.NORTH,f );


    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 213, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 184, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(156, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(46, 46, 46)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(70, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    /**
    * @param args the command line arguments
    */
    //}
    public void propertyChange(java.beans.PropertyChangeEvent pe) {

        System.out.println("received event or callback from "+pe.getPropagationId());

    }

    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

                new ServerCam().setVisible(true);
               // new ServerCam().initComponents();
               // new ServerCam().Iniciacamera();
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JPanel jPanel1;
    // End of variables declaration

}
J

Coloca um breakepoint aqui:

DSFilterInfo[][] dsi = DSCapture.queryDevices();

e olha em qual índice seu dispositivo foi detectado.

J

resolvi, foi so definir o layout do jpanel, engracado quando eu usava com jmf nao tive esse problema

U

Eu estou tentando a alguns tempo gravar video com audio utilizando o DSJ (Direct Show Java), mas não consigo. Somente o video é reproduzido. Alguem poderia me ajudar?

O código é o seguinte:

public void createGraph() {

javax.swing.JFrame f = new javax.swing.JFrame("dsj SimpleCapture");

    /** queryDevices returns video device infos in slot 0 / audio device infos in slot 1 **/
    DSFilterInfo[][] dsi = DSCapture.queryDevices();

    //
    /** this sample only uses video **/       
    graph = new DSCapture(DSFiltergraph.RENDER_NATIVE,
            dsi[0][1],
            true, //Capturar audio do dispositivo de video                
            dsi[1][0], //Dispositivo de audio
            this); //Instância de objeto que implemente PropertyChangeListener
    graph.lockVolume(5f);
    graph.setPreview();                

    f.add(java.awt.BorderLayout.CENTER, graph.asComponent());

    f.add(java.awt.BorderLayout.SOUTH, new SwingMovieController(graph));

    final javax.swing.JButton toFile = new javax.swing.JButton("set capture file");

    toFile.addActionListener(new java.awt.event.ActionListener() {

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {

            if (graph.getState() == DSCapture.PREVIEW) {

                /* capture to a Windows Media file using the default profile */
                
                //Aqui o video é gravado
                graph.setCaptureFile("captureTest.avi", DSFilterInfo.doNotRender(), DSFilterInfo.doNotRender(), true);

                toFile.setText("set preview");

                /* start recording right away. Outcomment to control this from GUI */

                graph.record();

            } else {

                graph.setPreview();

                toFile.setText("set capture file");

            }

        }
    });
J

você precisa aprender como o directshow funciona. Ele é um grafo com vários filtros interligados. Se você captura apenas vídeo, é porque um filtro de áudio não foi conectado na sua aplicação. Pega a documentação da dsj e dá uma lida, faça o mesmo na api do directshow.

ViniGodoy

Por favor, evite letras maiúsculas ao postar o texto ou o título dos tópicos.
Não há porque querer chamar tanta atenção.

Criado 29 de julho de 2010
Ultima resposta 27 de mar. de 2012
Respostas 7
Participantes 4