Quantcast
Channel: Programação - GUJ
Viewing all articles
Browse latest Browse all 33093

Capturar imagem da web cam e salvar a cada 1 segundo

$
0
0

@Jonathan_Galdino escreveu:

Olá!
Estou fazendo um projeto em que a webcam padrão tira fotos a cada 1 segundo utilizando o opencv.
Por enquanto ,nesse code, ao clique do botão capturar você seleciona a pasta onde quer e ele captura uma foto. É necessario um loop para fazer isso? E qual a melhor opção para o usuario para ele parar a gravação, um jButton ou um atalho do teclado?

public class jfmPrincipal extends javax.swing.JFrame {

    VideoCaptura webCam;
    ExibeQuadro exibeQuadro;
    Thread executor;
  private DaemonThread myThread = null;
    int count = 0;
    VideoCapture webSource = null;

    Mat frame = new Mat();
    MatOfByte mem = new MatOfByte();


    class DaemonThread implements Runnable
    {
    protected volatile boolean runnable = false;

    @Override
    public  void run()
    {
        synchronized(this)
        {
            while(runnable)
            {
                if(webSource.grab())
                {
    try
                        {
                            webSource.retrieve(frame);
   Highgui.imencode(".bmp", frame, mem);
   Image im = ImageIO.read(new ByteArrayInputStream(mem.toArray()));

   BufferedImage buff = (BufferedImage) im;
   Graphics g=jlbCaptura.getGraphics();

   if (g.drawImage(buff, 0, 0, getWidth(), getHeight() -150 , 0, 0, buff.getWidth(), buff.getHeight(), null))

   if(runnable == false)
                            {
    System.out.println("Going to wait()");
    this.wait();
   }
}
catch(Exception ex)
                         {
   System.out.println("Error");
                         }
                }
            }
        }
     }
   }
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         

        int returnVal = jFileChooser1.showSaveDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
        File file = jFileChooser1.getSelectedFile();
        Highgui.imwrite(file.getPath(), frame);
    } else {
        System.out.println("Acesso negado.");
    }
}

Mensagens: 8

Participantes: 2

Ler tópico completo


Viewing all articles
Browse latest Browse all 33093