liudr
Full Member
Offline
Posts: 175
Simple PS3Eye camera properties dialog
Dec 1st , 2009, 6:52pm
Instructions are inside the comment. The GetAWB() is not implemented yet. /* Copy this to your setup() after initializing camera. SwingUtilities.invokeLater(new Runnable() { public void run() { pd = new PropertyDialog(); } }); Copy this outside your setup() or draw() int exposurePS3Eye=80; int gainPS3Eye=5; PropertyDialog pd; Store this in a separate file say gui.pde in your main sketch folder. */ import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import java.text.*; import java.util.*; class PropertyDialog implements ChangeListener { JFrame jfrm; JLabel jlabGain; JLabel jlabExposure; JLabel jlabRed; JLabel jlabGreen; JLabel jlabBlue; JLabel jlabInfo; JSlider jsldrGain; JSlider jsldrExposure; JSlider jsldrRed; JSlider jsldrGreen; JSlider jsldrBlue; JCheckBox jcbAWB; DecimalFormat df; PS3Eye p; PropertyDialog(PS3Eye pp) { p=pp; jfrm = new JFrame("Camera properties"); jfrm.getContentPane().setLayout(new FlowLayout()); jfrm.setSize(340, 520); jfrm.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); df = new DecimalFormat("#;-#"); setupSliders(); setupLabels(); jcbAWB = new JCheckBox("Automatic White Balance"); jsldrGain.addChangeListener(this); jsldrExposure.addChangeListener(this); jsldrRed.addChangeListener(this); jsldrGreen.addChangeListener(this); jsldrBlue.addChangeListener(this); jcbAWB.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { p.AutoAWB(((JCheckBox)(ie.getItem())).isSelected()); } }); Container cp = jfrm.getContentPane(); cp.add(jlabGain); cp.add(jsldrGain); cp.add(jlabExposure); cp.add(jsldrExposure); cp.add(jlabRed); cp.add(jsldrRed); cp.add(jlabGreen); cp.add(jsldrGreen); cp.add(jlabBlue); cp.add(jsldrBlue); cp.add(new JLabel(" ")); cp.add(jcbAWB); cp.add(new JLabel(" ")); cp.add(jlabInfo); } public void stateChanged(ChangeEvent ce) { showSettings(ce); } void setupSliders() { jsldrGain = new JSlider(0, 79); jsldrExposure = new JSlider(0, 511); jsldrRed = new JSlider(0, 255); jsldrBlue = new JSlider(0, 255); jsldrGreen = new JSlider(0, 255); jsldrGain.setMajorTickSpacing(10); jsldrExposure.setMajorTickSpacing(64); jsldrRed.setMajorTickSpacing(32); jsldrBlue.setMajorTickSpacing(32); jsldrGreen.setMajorTickSpacing(32); Hashtable table = new Hashtable(); for(int i = 0; i <= 255; i += 32) table.put(new Integer(i), new JLabel("" + i)); Hashtable table2 = new Hashtable(); for(int i = 0; i <= 511; i += 64) table2.put(new Integer(i), new JLabel("" + i)); Hashtable table3 = new Hashtable(); for(int i = 0; i <= 79; i += 10) table3.put(new Integer(i), new JLabel("" + i)); jsldrRed.setLabelTable(table); jsldrGreen.setLabelTable(table); jsldrBlue.setLabelTable(table); jsldrExposure.setLabelTable(table2); jsldrGain.setLabelTable(table3); jsldrGain.setPaintTicks(true); jsldrExposure.setPaintTicks(true); jsldrRed.setPaintTicks(true); jsldrBlue.setPaintTicks(true); jsldrGreen.setPaintTicks(true); jsldrGain.setPaintLabels(true); jsldrExposure.setPaintLabels(true); jsldrRed.setPaintLabels(true); jsldrBlue.setPaintLabels(true); jsldrGreen.setPaintLabels(true); Dimension sldrSize = new Dimension(240, 60); jsldrGain.setPreferredSize(sldrSize); jsldrExposure.setPreferredSize(sldrSize); jsldrRed.setPreferredSize(sldrSize); jsldrBlue.setPreferredSize(sldrSize); jsldrGreen.setPreferredSize(sldrSize); jsldrGain.setValue(p.GetGain()); jsldrExposure.setValue(p.GetExposure()); byte r=127, g=127, b=127; jsldrRed.setValue((int)r); jsldrGreen.setValue((int)g); jsldrBlue.setValue((int)b); } void setupLabels() { jlabGain = new JLabel("Gain"); jlabExposure = new JLabel("Exposure"); jlabRed = new JLabel("Red"); jlabGreen = new JLabel("Green"); jlabBlue = new JLabel("Blue"); Dimension labSize = new Dimension(60, 25); jlabRed.setPreferredSize(labSize); jlabExposure.setPreferredSize(labSize); jlabGain.setPreferredSize(labSize); jlabBlue.setPreferredSize(labSize); jlabGreen.setPreferredSize(labSize); jlabInfo = new JLabel(""); jlabInfo.setPreferredSize(new Dimension(110, 100)); showSettings(); } void showSettings() { String bal; jlabInfo.setText("<html>"+"<br>Gain: " +df.format(jsldrGain.getValue()) +"<br>Exposure: " +df.format(jsldrExposure.getValue()) +"<br>Red: " +df.format(jsldrRed.getValue()) +"<br>Green: " +df.format(jsldrGreen.getValue()) +"<br>Blue: " +df.format(jsldrBlue.getValue())); } void showSettings(ChangeEvent ce) { String bal; jlabInfo.setText("<html>"+"<br>Gain: " +df.format(jsldrGain.getValue()) +"<br>Exposure: " +df.format(jsldrExposure.getValue()) +"<br>Red: " +df.format(jsldrRed.getValue()) +"<br>Green: " +df.format(jsldrGreen.getValue()) +"<br>Blue: " +df.format(jsldrBlue.getValue())); if (ce.getSource()==jsldrExposure) { p.SetExposure(exposurePS3Eye=jsldrExposure.getValue()); return; } else if (ce.getSource()==jsldrGain) { p.SetGain(gainPS3Eye=jsldrGain.getValue()); return; } else if (ce.getSource()==jsldrRed||ce.getSource()==jsldrGreen||ce.getSource()==jsldrBlue ) { p.SetWhiteBalance((byte)jsldrRed.getValue(), (byte)jsldrGreen.getValue(), (byte)jsldrBlue.getValue()); return; } } }