⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 processeffectlauncher.java

📁 能够检测到人脸
💻 JAVA
字号:
package visage_v3_2;/*Autor: Adel Restom adel_restom@yahoo.com*/import javax.media.*;import javax.media.control.TrackControl;import javax.media.format.*;import javax.swing.*;import javax.media.protocol.*;import java.awt.*;/*  This class adds the 'ProcessEffect' effect to the video stream after instantiating a processor.  ALL THE CODE WRITTEN HERE IS TAKEN FROM SUN'S 'RotationEffect' CODE SAMPLE, SLIGHT MODIFICATIONS WHERE MADE.*/public class ProcessEffectLauncher implements ControllerListener {  Processor processor;  Object waitSync = new Object();  boolean stateTransitionOK = true;  public ProcessEffectLauncher()  {}  public Processor open(DataSource ds,CaptureDeviceInfo cdi, Frame frame)  {    try //Instantiate a processor    {      processor = Manager.createProcessor(ds);    }    catch (Exception e)    {      JOptionPane.showMessageDialog(frame,"Failed to create a processor",null,JOptionPane.ERROR_MESSAGE);      System.exit(-1);    }    processor.addControllerListener(this);    //Put the Processor into configured state.    processor.configure();    if (!waitForState(processor.Configured))    {      JOptionPane.showMessageDialog(frame,"Failed to configure the processor",null,JOptionPane.ERROR_MESSAGE);      System.exit(-1);    }    //So We can use it as a player.    processor.setContentDescriptor(null);    //Obtain the track controls.    TrackControl tc[] = processor.getTrackControls();    if (tc == null)    {      JOptionPane.showMessageDialog(frame,"Failed to obtain track controls from the processor",null,JOptionPane.ERROR_MESSAGE);      System.exit(-1);    }    //Search for the track control for the video track.    TrackControl videoTrack = null;    for (int i = 0; i < tc.length; i++)    {      if (tc[i].getFormat() instanceof VideoFormat)      {        {          videoTrack = tc[i];          break;        }      }    }    if (videoTrack == null)    {      JOptionPane.showMessageDialog(frame,"The input media does not contain a video track",null,JOptionPane.ERROR_MESSAGE);      System.exit(-1);    }    //Instantiate and set the frame access codec to the data flow path.    try    { //If the video stream is flipped, flip it back to the normal state ( my code )      String format = videoTrack.getFormat().toString();      Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();      double width = screenSize.getWidth();      double height = screenSize.getHeight();      if( format.endsWith(", Flipped") )      {        Codec codec[] = { /*new HorizontalFlip(cdi),*/ new ProcessEffect(cdi,frame.model,frame,(int)(width/2d),(int)(height/2d))};        frame.xScale = width / 80d;        frame.yScale = height / 60d;        SpinnerModel xModel = new SpinnerNumberModel(frame.xScale, 1, frame.xScale*2, 0.5);        frame.xSpinner.setModel(xModel);        SpinnerModel yModel = new SpinnerNumberModel(frame.yScale, 1, frame.yScale*2, 0.5);        frame.ySpinner.setModel(yModel);        videoTrack.setCodecChain(codec);      }      else //If not flipped, add only the 'ProcessEffect' effect      {        Codec codec[] = { /*new HorizontalFlip(cdi),*/new ProcessEffect(cdi,frame.model,frame,(int)(width/2d),(int)(height/2d))};        frame.xScale = width / 80d;        frame.yScale = height / 60d;        SpinnerModel xModel = new SpinnerNumberModel(frame.xScale, 1, frame.xScale*2, 0.1);        frame.xSpinner.setModel(xModel);        SpinnerModel yModel = new SpinnerNumberModel(frame.yScale, 1, frame.yScale*2, 0.1);        frame.ySpinner.setModel(yModel);        videoTrack.setCodecChain(codec);      }    }    catch (UnsupportedPlugInException e)    {      JOptionPane.showMessageDialog(frame,"The processor does not support effects",null,JOptionPane.ERROR_MESSAGE);      System.exit(-1);    }    //Realize the processor.    processor.prefetch();    if (!waitForState(processor.Prefetched))    {      JOptionPane.showMessageDialog(frame,"Failed to realize the processor",null,JOptionPane.ERROR_MESSAGE);      System.exit(-1);    }    //Start the processor.    processor.start();    return processor;  }  /**   * Block until the processor has transitioned to the given state.   * Return false if the transition failed.   */  boolean waitForState(int state)  {    synchronized (waitSync)    {      try      {        while (processor.getState() != state && stateTransitionOK)          waitSync.wait();      }      catch (Exception e) {}    }    return stateTransitionOK;  }  /**   * Controller Listener.   */  public void controllerUpdate(ControllerEvent evt)  {    if (evt instanceof ConfigureCompleteEvent || evt instanceof RealizeCompleteEvent || evt instanceof PrefetchCompleteEvent) {      synchronized (waitSync)      {        stateTransitionOK = true;        waitSync.notifyAll();      }    }    else if (evt instanceof ResourceUnavailableEvent)    {      synchronized (waitSync)      {        stateTransitionOK = false;        waitSync.notifyAll();      }    }    else if (evt instanceof EndOfMediaEvent)    {      processor.close();      System.exit(0);    }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -