📄 frame.java~3~
字号:
package visage_v3_2;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.media.*;
import svm.*;
import javax.media.protocol.*;
/**
* <p>Title: Visage V3.2</p>
* <p>Description: 'An application to use the face as a mouse'</p>
* <p>Copyright: Copyright (c) 2006</p>
* <p>Company: </p>
* @author Adel Restom adel_restom@yahoo.com
* @version 3.2
*/
public class Frame extends JFrame
{
Processor processor;
svm_model model;
JButton detect = new JButton();
boolean detectFaces = false;
boolean track = false,drawEyes = true,drawNose = true,drawBte = false,
drawROI = false,drawMotion = false,drawBlink = true,drawBrows = true;
PushBufferDataSource pbds = null;
CaptureDeviceInfo cdi;
Component vc,cc;
Preview preview;
int cThreshold = 20;
int bThreshold = 30;
int brThreshold = 160;
double blinkLength = 0.5;
boolean enable = false;
double xScale = 0,yScale = 0;
/////////////////////////////////////////////////
JPanel contentPane;
MenuBar jMenuBar1 = new MenuBar();
Menu file = new Menu();
MenuItem exit = new MenuItem();
Menu help = new Menu();
MenuItem about = new MenuItem();
BorderLayout borderLayout1 = new BorderLayout();
JButton refresh = new JButton();
JButton stop = new JButton();
JCheckBox drawE = new JCheckBox();
JCheckBox drawR = new JCheckBox();
JCheckBox drawN = new JCheckBox();
JCheckBox drawB = new JCheckBox();
JCheckBox drawM = new JCheckBox();
SpinnerModel cModel = new SpinnerNumberModel(cThreshold, 1, 255, 1);
JSpinner cThresholdSpinner = new JSpinner(cModel);
JLabel jLabel1 = new JLabel();
JPanel jPanel2 = new JPanel();
SpinnerModel bModel = new SpinnerNumberModel(bThreshold, 1, 525, 1);
JSpinner bThresholdSpinner = new JSpinner(bModel);
JLabel jLabel4 = new JLabel();
JCheckBox drawBl = new JCheckBox();
JLabel jLabel5 = new JLabel();
SpinnerModel bLenModel = new SpinnerNumberModel(blinkLength, 0.1d, 1d, 0.1d);
JSpinner bLength = new JSpinner(bLenModel);
JLabel jLabel6 = new JLabel();
JButton EnVis = new JButton();
JPanel jPanel4 = new JPanel();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
SpinnerModel brModel = new SpinnerNumberModel(brThreshold, 1, 255, 5);
JSpinner browThresholdSpinner = new JSpinner(brModel);
JPanel jPanel1 = new JPanel();
JCheckBox drawBr = new JCheckBox();
JPanel jPanel3 = new JPanel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JSpinner xSpinner = new JSpinner();
JLabel jLabel9 = new JLabel();
JSpinner ySpinner = new JSpinner();
//Construct the frame
public Frame(WaitFrame wFrame)
{
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try
{
jbInit();
model = svm.svm_load_model("Model.txt");
findCaptureDevice();
this.getContentPane().setCursor(Cursor.getDefaultCursor());
wFrame.hide();
}
catch(Exception e) {
e.printStackTrace();
}
}
////////////////////////////////////////
private void findCaptureDevice()
{
DevicesFinder devicesFinder = new DevicesFinder();
pbds = devicesFinder.findDevices(this);
if( pbds != null )
{
ProcessEffectLauncher pel = new ProcessEffectLauncher();
processor = pel.open(pbds, cdi, this);
processor.start();
vc = processor.getVisualComponent();
vc.setLocation(5,2);
vc.setSize(new Dimension(320,240));
this.getContentPane().add(vc);
cc = processor.getControlPanelComponent();
cc.setSize(new Dimension(35,20));
cc.setLocation(488,78);
this.getContentPane().add(cc);
}
}
////////////////////////////////////////
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.setResizable(false);
this.setSize(new Dimension(689, 296));
this.setTitle("Visage V3.2");
this.addWindowFocusListener(new Frame_this_windowFocusAdapter(this));
file.setLabel("File");
exit.setLabel("Exit");
exit.addActionListener(new Frame_exit_ActionAdapter(this));
help.setLabel("Help");
about.setLabel("About");
about.addActionListener(new Frame_about_ActionAdapter(this));
detect.setBounds(new Rectangle(332, 1, 120, 23));
detect.setText("Detect The Face");
detect.addActionListener(new Frame_detect_actionAdapter(this));
refresh.addActionListener(new Frame_refresh_actionAdapter(this));
refresh.setText("Refresh Preview");
refresh.addActionListener(new Frame_refresh_actionAdapter(this));
refresh.setBounds(new Rectangle(332, 76, 120, 23));
stop.setText("Stop Tracking");
stop.addActionListener(new Frame_stop_actionAdapter(this));
stop.setBounds(new Rectangle(332, 51, 120, 23));
stop.setEnabled(false);
drawE.setSelected(true);
drawE.setText("Show Eyes");
drawE.setBounds(new Rectangle(14, 6, 88, 23));
drawE.addActionListener(new Frame_drawE_actionAdapter(this));
drawR.setText("Show ROIs");
drawR.setBounds(new Rectangle(113, 59, 88, 23));
drawR.addActionListener(new Frame_drawR_actionAdapter(this));
drawN.setSelected(true);
drawN.setText("Show Nose");
drawN.setBounds(new Rectangle(14, 34, 88, 23));
drawN.addActionListener(new Frame_drawN_actionAdapter(this));
drawB.setText("Show BTE");
drawB.setBounds(new Rectangle(14, 62, 88, 23));
drawB.addActionListener(new Frame_drawB_actionAdapter(this));
drawM.setText("Show Motion");
drawM.setBounds(new Rectangle(14, 90, 88, 23));
drawM.addActionListener(new Frame_drawM_actionAdapter(this));
cThresholdSpinner.setBounds(new Rectangle(38, 50, 43, 18));
cThresholdSpinner.addChangeListener(new SpinnerListener(this,0));
jLabel1.setText("Motion Detection");
jLabel1.setBounds(new Rectangle(18, 31, 83, 15));
jPanel2.setBorder(BorderFactory.createLineBorder(Color.black));
jPanel2.setBounds(new Rectangle(334, 104, 222, 137));
jPanel2.setLayout(null);
bThresholdSpinner.setBounds(new Rectangle(38, 94, 43, 18));
bThresholdSpinner.addChangeListener(new SpinnerListener(this,1));
jLabel4.setText("Blink Detection");
jLabel4.setBounds(new Rectangle(23, 75, 73, 15));
drawBl.setText("Show Blink");
drawBl.setBounds(new Rectangle(112, 7, 83, 23));
drawBl.addActionListener(new Frame_drawBl_actionAdapter(this));
drawBl.setSelected(true);
jLabel5.setText("Blink Length");
jLabel5.setBounds(new Rectangle(29, 10, 60, 15));
bLength.addChangeListener(new SpinnerListener(this,2));
bLength.setBounds(new Rectangle(18, 37, 37, 18));
jLabel6.setText("Second");
jLabel6.setBounds(new Rectangle(60, 39, 40, 15));
EnVis.setText("Enable Visage");
EnVis.addActionListener(new Frame_EnVis_actionAdapter(this));
EnVis.setBounds(new Rectangle(332, 26, 120, 23));
EnVis.setEnabled(false);
EnVis.setForeground(Color.red);
jPanel4.setBorder(BorderFactory.createLineBorder(Color.black));
jPanel4.setBounds(new Rectangle(562, 3, 118, 161));
jPanel4.setLayout(null);
jLabel7.setFont(new java.awt.Font("Dialog", 0, 14));
jLabel7.setText("Thresholds");
jLabel7.setBounds(new Rectangle(22, 6, 74, 15));
jLabel8.setText("Eyebrow Detection");
jLabel8.setBounds(new Rectangle(13, 119, 93, 15));
browThresholdSpinner.addChangeListener(new SpinnerListener(this,3));
browThresholdSpinner.setBounds(new Rectangle(38, 138, 43, 18));
jPanel1.setBorder(BorderFactory.createLineBorder(Color.black));
jPanel1.setBounds(new Rectangle(562, 169, 118, 72));
jPanel1.setLayout(null);
drawBr.setSelected(true);
drawBr.setText("Show Eyebrows");
drawBr.setBounds(new Rectangle(112, 35, 107, 23));
drawBr.addActionListener(new Frame_drawBr_actionAdapter(this));
jPanel3.setBorder(BorderFactory.createLineBorder(Color.black));
jPanel3.setBounds(new Rectangle(456, 3, 100, 70));
jPanel3.setLayout(null);
jLabel2.setText("Scale Factor");
jLabel2.setBounds(new Rectangle(17, 3, 67, 15));
jLabel3.setText("x axis");
jLabel3.setBounds(new Rectangle(8, 23, 34, 15));
xSpinner.setBounds(new Rectangle(45, 22, 43, 18));
xSpinner.addChangeListener(new SpinnerListener(this,4));
jLabel9.setText("y axis");
jLabel9.setBounds(new Rectangle(8, 44, 31, 15));
ySpinner.setBounds(new Rectangle(45, 43, 43, 18));
ySpinner.addChangeListener(new SpinnerListener(this,5));
file.add(exit);
help.add(about);
jMenuBar1.add(file);
jMenuBar1.add(help);
this.setMenuBar(jMenuBar1);
jPanel4.add(jLabel7, null);
jPanel4.add(jLabel1, null);
jPanel4.add(browThresholdSpinner, null);
jPanel4.add(jLabel8, null);
jPanel4.add(cThresholdSpinner, null);
jPanel4.add(jLabel4, null);
jPanel4.add(bThresholdSpinner, null);
contentPane.add(jPanel3, null);
contentPane.add(jPanel1, null);
jPanel1.add(jLabel5, null);
jPanel1.add(jLabel6, null);
jPanel1.add(bLength, null);
contentPane.add(jPanel2, null);
contentPane.add(EnVis, null);
contentPane.add(detect, null);
contentPane.add(stop, null);
contentPane.add(refresh, null);
jPanel2.add(drawE, null);
jPanel2.add(drawN, null);
jPanel2.add(drawB, null);
jPanel2.add(drawM, null);
jPanel2.add(drawBl, null);
jPanel2.add(drawBr, null);
jPanel2.add(drawR, null);
contentPane.add(jPanel4, null);
jPanel3.add(jLabel2, null);
jPanel3.add(xSpinner, null);
jPanel3.add(jLabel3, null);
jPanel3.add(ySpinner, null);
jPanel3.add(jLabel9, null);
}
//File | Exit action performed
public void exit_actionPerformed(ActionEvent e)
{
if( processor != null )
{
processor.stop();
processor.close();
this.remove(vc);
this.remove(cc);
}
System.exit(0);
}
//Help | About action performed
public void about_actionPerformed(ActionEvent e) {
Frame_AboutBox dlg = new Frame_AboutBox(this);
Dimension dlgSize = dlg.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
dlg.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
dlg.setModal(true);
dlg.pack();
dlg.show();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -