Page 206 - The Definitive Guide to Building Java Robots
P. 206
Preston_5564C06.fm Page 187 Friday, September 23, 2005 5:13 AM
CHAPTER 6 ■ VISION 187
public static final String FILTER_SMOOTH = "8";
public static final String FILTER_SHARP = "9";
public static final String FILTER_RESIZE = "10";
public static final String FILTER_HOUGH_LINES = "11";
// generic method for processing
public BufferedImage process(FilterParameters parms) {
BufferedImage dstImg = null;
if (parms.getName().equalsIgnoreCase(FILTER_RGB_TO_GREY)) {
dstImg = rgbToGrey(parms.getImage());
}
if (parms.getName().equalsIgnoreCase(FILTER_MOTION)) {
dstImg = backgroundSubtract(parms.getImage());
}
if (parms.getName().equalsIgnoreCase(FILTER_THRESHHOLD)) {
int min = ((Integer) parms.getParameters().get(0)).intValue();
int max = ((Integer) parms.getParameters().get(1)).intValue();
Boolean transparent = Boolean.FALSE;
if (parms.getParameters().get(2) != null) {
transparent = (Boolean) parms.getParameters().get(2);
}
dstImg = threshold(parms.getImage(), min, max,➥
transparent.booleanValue());
}
if (parms.getName().equalsIgnoreCase(FILTER_THRESHHOLD_COLOR)) {
int min = ((Integer) parms.getParameters().get(0)).intValue();
int max = ((Integer) parms.getParameters().get(1)).intValue();
Color c = (Color) parms.getParameters().get(2);
dstImg = thresholdColor(parms.getImage(), min, max, c);
}
if (parms.getName().equalsIgnoreCase(FILTER_COLOR)) {
Color c = (Color) parms.getParameters().get(0);
dstImg = filterColor(parms.getImage(), c);
}
if (parms.getName().equalsIgnoreCase(FILTER_COLOR_RATIO)) {
ColorGram cg = (ColorGram) parms.getParameters().get(0);
dstImg = colorRatio(parms.getImage(), cg);
}
if (parms.getName().equalsIgnoreCase(FILTER_EDGE)) {
dstImg = sobelGradMag(parms.getImage());
}
if (parms.getName().equalsIgnoreCase(FILTER_SMOOTH)) {
dstImg = smooth(parms.getImage());
}
if (parms.getName().equalsIgnoreCase(FILTER_SHARP)) {
dstImg = sharpen(parms.getImage());
}