Page 203 - The Definitive Guide to Building Java Robots
P. 203
Preston_5564C06.fm Page 184 Friday, September 23, 2005 5:13 AM
184 CHAPTER 6 ■ VISION
The main example converts the image on the left from color to greyscale, which is shown
in Example 6-10.
Example 6-10. DoubleWebCamViewer.java
package com.scottpreston.javarobot.chapter6;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import javax.swing.Box;
import javax.swing.BoxLayout;
public class DoubleWebCamViewer extends WebCamViewer {
// source / original image
private ImagePanel srcPanel = new ImagePanel();
// destination image
private ImagePanel dstPanel = new ImagePanel();
// filters (list of FilterParameters)
private ArrayList filters = new ArrayList();
// constructor with no camera
public DoubleWebCamViewer() throws Exception {
super(DEFAULT_CAMERA);
// separate init method
init2();
}
// constructor with camera name
public DoubleWebCamViewer(String camera) throws Exception {
super(camera);
// separate init method
init2();
}
// common initialization block
public void init2() throws Exception {
setTitle("Double Webcam Viewer");
// set frame properties
this.setSize(648, 270);
Box box = new Box(BoxLayout.X_AXIS);
box.add(srcPanel);
box.add(dstPanel);
// clear contents added in parent
this.getContentPane().removeAll();