Maybe my code can help you to get on the right track. I use
MarvinFramework and works amaizingly well.
Here's my code:
[CODE]
/**
Marvin Project <2007-2009>
Initial version by:
Danilo Rosetto Munoz
Fabio Andrijauskas
Gabriel Ambrosio Archanjo
site:
http://marvinproject.sourceforge.net
GPL
Copyright (C) <2007>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along
with this program; if not, write to the Free Software Foundation,
Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import marvin.gui.MarvinImagePanel;
import marvin.image.MarvinImage;
import marvin.image.MarvinImageMask;
import marvin.io.MarvinImageIO;
import marvin.plugin.MarvinImagePlugin;
import marvin.video.MarvinVideoManager;
@SuppressWarnings("serial")
public class Cam extends JFrame implements Runnable{
// GUI
private JPanel panelButton,
panelCenter;
private JButton buttonPlayStop, close;
private MarvinVideoManager videoManager;
private MarvinImagePanel videoPanel;
private MarvinImage imageIn;
private MarvinImage imageOut;
private MarvinImage imageLastFrame;
private MarvinImageMask imageMask;
private Thread thread;
private MarvinImagePlugin pluginImage;
private int cameraWidth,
cameraHeight;
public Cam(){
videoPanel = new MarvinImagePanel();
videoManager = new MarvinVideoManager(videoPanel);
videoManager.connect();
cameraWidth = videoManager.getCameraWidth();
cameraHeight = videoManager.getCameraHeight();
imageLastFrame = new MarvinImage(cameraWidth,cameraHeight);
imageMask = MarvinImageMask.NULL_MASK;
loadGUI();
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
thread = new Thread(this);
thread.start();
}
private void loadGUI(){
setTitle("Video Sample - Filters");
// Buttons
ButtonHandler l_handler = new ButtonHandler();
buttonPlayStop = new JButton("Snapshot");
close = new JButton("Close");
buttonPlayStop.addActionListener(l_handler);
close.addActionListener(l_handler);
// Panels
panelButton = new JPanel();
panelButton.add(buttonPlayStop);
panelButton.add(close);
panelCenter = new JPanel(new BorderLayout());
panelCenter.add(videoPanel, BorderLayout.NORTH);
panelCenter.add(panelButton, BorderLayout.SOUTH);
Container l_container = getContentPane();
l_container.setLayout(new BorderLayout());
l_container.add(panelCenter, BorderLayout.CENTER);
setSize(cameraWidth,cameraHeight+65);
setResizable(false);
setVisible(true);
}
public void run(){
while(true){
imageIn = videoManager.getCapturedImage();
imageOut = videoManager.getResultImage();
if(pluginImage == null){
MarvinImage.copyColorArray(imageIn, imageOut);
}
if(pluginImage != null){
pluginImage.process(imageIn, imageOut, null, imageMask, false);
}
MarvinImage.copyColorArray(imageIn, imageLastFrame);
videoManager.updatePanel();
}
}
public void snapshot(){
MarvinImage snapshot = videoManager.getResultImage();
snapshot.update();
MarvinImageIO.saveImage(snapshot, "./snapshot.JPG");
}
private class ButtonHandler implements ActionListener{
public void actionPerformed(ActionEvent a_event){
if(a_event.getSource() == buttonPlayStop){
snapshot();
} else if(a_event.getSource() == close){
dispose();
videoManager.disconnect();
}
}
}
}
[/CODE]
This takes snapshoots. To take a snapshoot every 40 sec you just have
to add maybe 2 more Lines of code. I hope this can help you.