Advertisement
Guest User

Untitled

a guest
Apr 16th, 2013
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.98 KB | None | 0 0
  1. package marvin.test;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Container;
  5. import java.awt.Label;
  6. import java.awt.TextField;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.MouseEvent;
  10. import java.awt.event.MouseMotionListener;
  11. import javax.swing.JButton;
  12. import javax.swing.JFrame;
  13. import javax.swing.JPanel;
  14. import org.marvinproject.image.color.invert.Invert;
  15. import marvin.test.SkinColorDetection;
  16. import com.googlecode.javacv.FrameGrabber;
  17. import com.googlecode.javacv.OpenCVFrameGrabber;
  18. import com.googlecode.javacv.cpp.opencv_core.IplImage;
  19. import marvin.test.EdgeDetector;
  20. import marvin.util.MarvinAttributes;
  21. import marvin.gui.MarvinImagePanel;
  22. import marvin.image.MarvinImage;
  23. import marvin.image.MarvinImageMask;
  24. import marvin.plugin.MarvinImagePlugin;
  25. import marvin.plugin.MarvinPlugin;
  26.  
  27.  
  28. @SuppressWarnings("serial")
  29. public class MarvinTest extends JFrame implements ActionListener, MouseMotionListener
  30. {
  31.     public static  MarvinImagePanel     imagePanel;
  32.     private MarvinImage         image,
  33.                                 backupImage;
  34.     private JPanel              panelBottom;
  35.     private JButton             buttonGray,
  36.                                 buttonEdgeDetector,
  37.                                 buttonInvert,
  38.                                 buttonReset;
  39.    
  40.     private MarvinImagePlugin   imagePlugin;
  41.     FrameGrabber grabber = new OpenCVFrameGrabber("./res/3.wmv");  
  42.     public static Container l_c;
  43.     Label x,y;
  44.     TextField tfx,tfy;
  45.     IplImage firstframe;
  46.     public MarvinTest()
  47.     {
  48.         super("MarvinTest");
  49.        
  50.         // Create Graphical Interface
  51.         buttonGray = new JButton("Skin color");
  52.         buttonGray.addActionListener(this);
  53.         buttonEdgeDetector = new JButton("EdgeDetector");
  54.         buttonEdgeDetector.addActionListener(this);
  55.         buttonInvert = new JButton("Invert");
  56.         buttonInvert.addActionListener(this);
  57.         buttonReset = new JButton("Reset");
  58.         buttonReset.addActionListener(this);
  59.         x=new Label("X=");
  60.         y=new Label("Y=");
  61.         tfx=new TextField();
  62.         tfy=new TextField();
  63.         panelBottom = new JPanel();
  64.         panelBottom.add(x);
  65.         panelBottom.add(y);
  66.         panelBottom.add(tfx);
  67.         panelBottom.add(tfy);
  68.        
  69.         panelBottom.add(buttonGray);
  70.         panelBottom.add(buttonEdgeDetector);
  71.         panelBottom.add(buttonInvert);
  72.         panelBottom.add(buttonReset);
  73.        
  74.         // ImagePanel
  75.         imagePanel = new MarvinImagePanel();
  76.        
  77.        
  78.         l_c = getContentPane();
  79.         addMouseMotionListener(this);
  80.         l_c.setLayout(new BorderLayout());
  81.         l_c.add(panelBottom, BorderLayout.SOUTH);
  82.         l_c.add(imagePanel, BorderLayout.NORTH);
  83.        
  84.        
  85.        
  86.         setSize(800,800);
  87.         setVisible(true);
  88.         // i removed thread declaration here , i was calling start method of Thread. t.start();
  89.         run();
  90.     }
  91.    
  92.     public static void main(String args[]){
  93.         MarvinTest t = new MarvinTest();
  94.         t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  95.        
  96.        
  97.     }
  98.    
  99.     public void actionPerformed(ActionEvent e){
  100.         //image = backupImage.clone();
  101.         MarvinPlugin l_plugin;
  102.         MarvinImagePlugin lplugin;
  103.         if(e.getSource() == buttonGray){
  104.             l_plugin=(MarvinPlugin)new SkinColorDetection();
  105.             lplugin=(MarvinImagePlugin)l_plugin;
  106.             lplugin.load();
  107.             //imagePlugin = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.color.skinColorDetection.jar");
  108.             imagePlugin=lplugin;
  109.             imagePlugin.process(image, image, null, MarvinImageMask.NULL_MASK, false);
  110.             image.update();
  111.            
  112.             imagePanel.setImage(image);
  113.             imagePanel.repaint();
  114.         }
  115.         else if(e.getSource() == buttonEdgeDetector){
  116.             l_plugin=(MarvinPlugin)new EdgeDetector();
  117.             lplugin=(MarvinImagePlugin)l_plugin;
  118.             lplugin.load();
  119.             imagePlugin=lplugin;
  120.             MarvinAttributes att=l_plugin.getAttributes();
  121.             //imagePlugin = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.edge.edgeDetector.jar");
  122.             imagePlugin.process(image, image, att, MarvinImageMask.NULL_MASK, false);
  123.         }
  124.         else if(e.getSource() == buttonInvert){
  125.             l_plugin=(MarvinPlugin)new Invert();
  126.             lplugin=(MarvinImagePlugin)l_plugin;
  127.             lplugin.load();
  128.             imagePlugin=lplugin;
  129.             //imagePlugin = MarvinPluginLoader.loadImagePlugin("org.marvinproject.image.color.invert.jar");
  130.             imagePlugin.process(image, image, null, MarvinImageMask.NULL_MASK, false);
  131.         }else
  132.         imagePanel.setImage(backupImage);
  133.     }
  134.     @Override
  135.     public void mouseDragged(MouseEvent e) {
  136.  
  137.     }
  138.  
  139.     @Override
  140.     public void mouseMoved(MouseEvent e) {
  141.        
  142.         tfx.setText("X="+e.getX());
  143.         tfy.setText("Y="+e.getY());
  144.     }
  145.    
  146.     IplImage img;
  147.     MarvinPlugin l_plugin;
  148.     MarvinImagePlugin lplugin;
  149.    
  150.      public  void run() {
  151.        
  152.          l_plugin=(MarvinPlugin)new SkinColorDetection();
  153.             lplugin=(MarvinImagePlugin)l_plugin;
  154.             lplugin.load();
  155.             imagePlugin=lplugin;
  156.            
  157.           try{
  158.               grabber.start();
  159.               img= grabber.grab();
  160.         while (img!=null) {
  161.                 img= grabber.grab();
  162.                image=new MarvinImage(img.getBufferedImage());
  163.                imagePlugin.process(image, image, null, MarvinImageMask.NULL_MASK, false);
  164.               image.update();
  165.                imagePanel.setImage(image);
  166.                imagePanel.repaint();
  167.     }
  168.    
  169.         }
  170.           catch(Exception e)
  171.            {
  172.                e.printStackTrace();
  173.            }
  174.        
  175. }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement