Page 237 - The Definitive Guide to Building Java Robots
P. 237
Preston_5564C06.fm Page 218 Friday, September 23, 2005 5:13 AM
218 CHAPTER 6 ■ VISION
for (int b = 0; b < pMax; b++) { // all pixels
for (int a = 0; a < angle_range; a = a + aRes) { // all angles
// created x coordinate from angles and distances
double xx = (a / (double)angle_range) * (double) w;
// created y coordinate from angles and distances
double yy = (b / (double) pMax) * (double) h;
// look at threshold of lines relative to max value of the
if (acc[b][a] > (hough_thresh * maxPoints)) {
// now find tangent lines
drawHoughLines(srcImg, b, a);
}
}
}
return srcImg;
}
private void drawHoughLines(BufferedImage img, int p, int theta) {
// h & w of image
int h = img.getHeight();
int w = img.getWidth();
double radians = (theta / 360.0) * Math.PI * 2;
// get line coordinates
int x = (int) (p * Math.cos(radians));
int y = (int) (p * Math.sin(radians));
double x1 = (double) x;
double y1 = (double) y;
double x2 = x;
double y2 = y;
//double tx = Math.cos(radians);
//double ty = Math.sin(radians);
// add all points on line in one direction
while (y1 > 0 && x1 < w && y1 < h && x1 > 0) {
x1 = (x1 + Math.sin(radians));
y1 = (y1 - Math.cos(radians));
}
// add all points on line in the other direction
while (y2 > 0 && x2 < w && y2 < h && x2 > 0) {
x2 = (x2 - Math.sin(radians));
y2 = (y2 + Math.cos(radians));
}