I have a solution that will work on a specific website. You can take a snapshot of the entire page and get a captcha image. Then divide the entire width of the captcha image by the total number of characters (usually it’s usually constant in full). Now we have individual captcha image characters. Collect all possible captcha characters by reloading the page.
After you have all the possible characters, after which you will get some captcha image, you can compare its characters with the images that we have and decide which letter or number it has.
Stages:
Collect the captcha image and separate it into separate characters.
private static BufferedImage cropImage(File filePath, int x, int y, int w, int h) { try { BufferedImage originalImgage = ImageIO.read(filePath); BufferedImage subImgage = originalImgage.getSubimage(x, y, w, h); return subImgage; } catch (IOException e) { e.printStackTrace(); return null; } }
Save all possible images in a folder 
Now read each image of the captcha symbol and compare it with all the other images in the specified folder. You can compare two images using pixel values. Public static float getDiff (File f1, File f2, width int, int height) throws IOException {BufferedImage bi1 = null; BufferedImage bi2 = null; bi1 = new BufferedImage (width, height, BufferedImage.TYPE_INT_ARGB); bi2 = new BufferedImage (width, height, BufferedImage.TYPE_INT_ARGB);
bi1 = ImageIO.read(f1); bi2 = ImageIO.read(f2); float diff = 0; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int rgb1 = bi1.getRGB(i, j); int rgb2 = bi2.getRGB(i, j); int b1 = rgb1 & 0xff; int g1 = (rgb1 & 0xff00) >> 8; int r1 = (rgb1 & 0xff0000) >> 16; int b2 = rgb2 & 0xff; int g2 = (rgb2 & 0xff00) >> 8; int r2 = (rgb2 & 0xff0000) >> 16; diff += Math.abs(b1 - b2); diff += Math.abs(g1 - g2); diff += Math.abs(r1 - r2); } } return diff; }
Whatever image is with a lower difference value, which is an actual match. Add its name to the string. After reading all the images, captcha
1's return line:
https://i.stack.imgur.com/FYPhd.pngIn the above image, the image indicates a number or symbol.
This only works for a simple captcha such as [
1
source share