static int ocr_walkInDirection(RGBImage img, int x, int y, int dx, int dy, float tolerance) { int length = 0; int w = img.w(), h = img.h(); RGB rgb = img.getPixel(x, y); while (x >= 0 && x < w && y >= 0 && y < h && rgbDiff(x, y) <= tolerance) { ++length; x += dx; y += dy; } ret length; }