public Letter[] getOpenCirclePositionAsLetters() { openCircle = getOpenCircle(); if (openCircle == null) { return null; } int x = openCircle.getLocation()[0] + (openCircle.getWidth() / 2); int y = openCircle.getLocation()[1] + (openCircle.getHeight() / 2); return getPostionLetters(x, y); }
/** * returns the Circles Bounds on the Captcha TODO geht nur bei x entlang sollte noch bei y gemacht * werden um bessere ergebnisse zu bekommen * * @param pixelObject * @param captcha * @return */ private int[] getBounds(PixelObject pixelObject) { if (pixelObject.getSize() < 5 || pixelObject.getArea() < minArea) { return null; } Letter let = pixelObject.toColoredLetter(); int r = let.getWidth() / 2; try { int ratio = pixelObject.getHeight() * 100 / pixelObject.getWidth(); if ((ratio > 95 && ratio < 105) || equalElements(let.getGrid()[r][0], let.getGrid()[0][r]) || equalElements(let.getGrid()[r][let.getWidth() - 1], let.getGrid()[0][r]) || equalElements(let.getGrid()[r][0], let.getGrid()[let.getWidth() - 1][r]) || equalElements( let.getGrid()[r][let.getWidth() - 1], let.getGrid()[let.getWidth() - 1][r])) { return new int[] {let.getLocation()[0] + r, let.getLocation()[1] + let.getWidth()}; } } catch (Exception e) { } java.util.List<int[]> best = new ArrayList<int[]>(); int h = let.getLocation()[1] + let.getHeight(); for (int x = let.getLocation()[0]; x < let.getLocation()[0] + let.getWidth(); x++) { int y = let.getLocation()[1]; int c = captcha.grid[x][y]; if (!isBackground(c)) { y++; for (; y < h; y++) { if (isBackground(captcha.grid[x][y])) { break; } } // if (oldy == y || h < y) continue; int oldy = y; for (; y < h; y++) { if (!isBackground(captcha.grid[x][y]) && equalElements(c, captcha.grid[x][y])) { break; } } if (oldy == y || h < y) { continue; } oldy = y; for (; y < h; y++) { if (isBackground(captcha.grid[x][y])) { break; } } if (oldy == y) { continue; } if (y == let.getHeight() && Math.abs(let.getHeight() - let.getWidth()) > 15) { continue; } if (best.size() > 0) { if (y > best.get(0)[0]) { best = new ArrayList<int[]>(); best.add(new int[] {x, y}); } else if (y == best.get(0)[1]) { best.add(new int[] {x, y}); } } else { best.add(new int[] {x, y}); } } } if (best.size() == 0) { return null; } else { int x = 0; for (int[] is : best) { x += is[0]; } return new int[] {x / best.size(), best.get(0)[1]}; } }