Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package marvin.test;
- import java.awt.BorderLayout;
- import java.awt.Container;
- import java.awt.Label;
- import java.awt.TextField;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseMotionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import org.marvinproject.image.color.invert.Invert;
- import marvin.test.SkinColorDetection;
- import com.googlecode.javacv.FrameGrabber;
- import com.googlecode.javacv.OpenCVFrameGrabber;
- import com.googlecode.javacv.cpp.opencv_core.IplImage;
- import marvin.test.EdgeDetector;
- import marvin.util.MarvinAttributes;
- import marvin.gui.MarvinImagePanel;
- import marvin.image.MarvinImage;
- import marvin.image.MarvinImageMask;
- import marvin.plugin.MarvinImagePlugin;
- import marvin.plugin.MarvinPlugin;
- @SuppressWarnings("serial")
- public class MarvinTest extends JFrame implements ActionListener, MouseMotionListener
- {
- public static MarvinImagePanel imagePanel;
- private MarvinImage image,
- backupImage;
- private JPanel panelBottom;
- private JButton buttonGray,
- buttonEdgeDetector,
- buttonInvert,
- buttonReset;
- private MarvinImagePlugin imagePlugin;
- FrameGrabber grabber = new OpenCVFrameGrabber("./res/3.wmv");
- public static Container l_c;
- Label x,y;
- TextField tfx,tfy;
- IplImage firstframe;
- public MarvinTest()
- {
- super("MarvinTest");
- // Create Graphical Interface
- buttonGray = new JButton("Skin color");
- buttonGray.addActionListener(this);
- buttonEdgeDetector = new JButton("EdgeDetector");
- buttonEdgeDetector.addActionListener(this);
- buttonInvert = new JButton("Invert");
- buttonInvert.addActionListener(this);
- buttonReset = new JButton("Reset");
- buttonReset.addActionListener(this);
- x=new Label("X=");
- y=new Label("Y=");
- tfx=new TextField();
- tfy=new TextField();
- panelBottom = new JPanel();
- panelBottom.add(x);
- panelBottom.add(y);
- panelBottom.add(tfx);
- panelBottom.add(tfy);
- panelBottom.add(buttonGray);
- panelBottom.add(buttonEdgeDetector);
- panelBottom.add(buttonInvert);
- panelBottom.add(buttonReset);
- // ImagePanel
- imagePanel = new MarvinImagePanel();
- l_c = getContentPane();
- addMouseMotionListener(this);
- l_c.setLayout(new BorderLayout());
- l_c.add(panelBottom, BorderLayout.SOUTH);
- l_c.add(imagePanel, BorderLayout.NORTH);
- setSize(800,800);
- setVisible(true);
- // i removed thread declaration here , i was calling start method of Thread. t.start();
- run();
- }
- public static void main(String args[]){
- MarvinTest t = new MarvinTest();
- t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- public void actionPerformed(ActionEvent e){
- //image = backupImage.clone();
- MarvinPlugin l_plugin;
- MarvinImagePlugin lplugin;
- if(e.getSource() == buttonGray){
- l_plugin=(MarvinPlugin)new SkinColorDetection();
- lplugin=(MarvinImagePlugin)l_plugin;
- lplugin.load();
- //imagePlugin = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.color.skinColorDetection.jar");
- imagePlugin=lplugin;
- imagePlugin.process(image, image, null, MarvinImageMask.NULL_MASK, false);
- image.update();
- imagePanel.setImage(image);
- imagePanel.repaint();
- }
- else if(e.getSource() == buttonEdgeDetector){
- l_plugin=(MarvinPlugin)new EdgeDetector();
- lplugin=(MarvinImagePlugin)l_plugin;
- lplugin.load();
- imagePlugin=lplugin;
- MarvinAttributes att=l_plugin.getAttributes();
- //imagePlugin = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.edge.edgeDetector.jar");
- imagePlugin.process(image, image, att, MarvinImageMask.NULL_MASK, false);
- }
- else if(e.getSource() == buttonInvert){
- l_plugin=(MarvinPlugin)new Invert();
- lplugin=(MarvinImagePlugin)l_plugin;
- lplugin.load();
- imagePlugin=lplugin;
- //imagePlugin = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.color.invert.jar");
- imagePlugin.process(image, image, null, MarvinImageMask.NULL_MASK, false);
- }else
- imagePanel.setImage(backupImage);
- }
- @Override
- public void mouseDragged(MouseEvent e) {
- }
- @Override
- public void mouseMoved(MouseEvent e) {
- tfx.setText("X="+e.getX());
- tfy.setText("Y="+e.getY());
- }
- IplImage img;
- MarvinPlugin l_plugin;
- MarvinImagePlugin lplugin;
- public void run() {
- l_plugin=(MarvinPlugin)new SkinColorDetection();
- lplugin=(MarvinImagePlugin)l_plugin;
- lplugin.load();
- imagePlugin=lplugin;
- try{
- grabber.start();
- img= grabber.grab();
- while (img!=null) {
- img= grabber.grab();
- image=new MarvinImage(img.getBufferedImage());
- imagePlugin.process(image, image, null, MarvinImageMask.NULL_MASK, false);
- image.update();
- imagePanel.setImage(image);
- imagePanel.repaint();
- }
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement