Esempio n. 1
0
  /**
   * Setzt den Owner (Parameterdump jas wird gelesen
   *
   * @param owner
   */
  public void setOwner(JAntiCaptcha owner) {
    this.owner = owner;
    jas = owner.getJas();
    errorAWeight = jas.getDouble("errorAWeight");
    errorbWeight = jas.getDouble("errorBWeight");
    coverageFaktorAWeight = jas.getDouble("coverageFaktorAWeight");
    coverageFaktorBWeight = jas.getDouble("coverageFaktorBWeight");
    intersectionDimensionWeight = jas.getDouble("intersectionDimensionWeight");
    intersectionAHeightWeight = jas.getDouble("intersectionAHeightWeight");
    intersectionAWidthWeight = jas.getDouble("intersectionAWidthWeight");
    cleftFaktor = jas.getDouble("cleftFaktor");
    minCleftSize = jas.getInteger("minCleftSize");
    preScanFilter = jas.getInteger("preScanFilter");
    preScanFaktor = jas.getInteger("preScanFaktor");
    overlayNoiseSize = jas.getInteger("overlayNoiseSize");
    scanStepX = jas.getInteger("scanstepx");
    scanStepY = jas.getInteger("scanstepy");
    prescanDivider = jas.getDouble("prescandivider");
    divider = jas.getDouble("divider");
    extensionCodeArguments[0] = this;
    if (jas.getString("comparatorExtension").length() > 0) {
      String[] ref = jas.getString("comparatorExtension").split("\\.");
      if (ref.length != 2) {
        if (Utilities.isLoggerActive()) {
          logger.severe("comparatorExtension should have the format Class.Method");
        }
      }
      String cl = ref[0];
      String methodname = ref[1];
      Class<?> newClass;
      try {
        newClass = Class.forName("jd.captcha.specials." + cl);

        extensionCodeMethod = newClass.getMethod(methodname, extensionCodeParameterTypes);

      } catch (Exception e) {
        JDLogger.exception(e);
      }
    }
  }
Esempio n. 2
0
  private double scanIntersection(
      int xx, int yy, int left, int top, int tmpIntersectionWidth, int tmpIntersectionHeight) {
    offset = new int[] {left, top};
    imgOffset = new int[] {xx, yy};
    intersectionDimension = new int[] {tmpIntersectionWidth, tmpIntersectionHeight};

    double tmpError;
    pixelAll = 0;
    tmpPixelBButNotA = 0;
    tmpPixelAButNotB = 0;
    tmpPixelBoth = 0;
    tmpCoverageFaktorA = 0;
    tmpCoverageFaktorB = 0;
    // long starter=Utilities.getTimer();
    bothElements.removeAllElements();
    elementGrid = new int[tmpIntersectionWidth][tmpIntersectionHeight];

    for (int x = 0; x < tmpIntersectionWidth; x += scanStepX) {
      for (int y = 0; y < tmpIntersectionHeight; y += scanStepY) {

        int pixelType = getPixelType(x, y, xx, yy, left, top);
        pixelAll++;

        switch (pixelType) {
          case 0:
            if (isCreateIntersectionLetter()) {
              intersectionGrid[x][y] = BOTHCOLOR;
            }
            if (cleftFaktor > 0) {
              getElement(
                  x, y, xx, yy, left, top, pixelType, elementGrid, element = new Vector<Integer>());
              if (element.size() > minCleftSize) {
                bothElements.add(element);
              }
            }
            tmpPixelBoth++;
            break;
          case 1:
            if (overlayNoiseSize <= 0
                || hasNeighbour(x, y, xx, yy, left, top, pixelType) > overlayNoiseSize) {
              tmpPixelBButNotA++;
              if (isCreateIntersectionLetter()) {
                intersectionGrid[x][y] = BNACOLOR;
              }
            } else {
              if (isCreateIntersectionLetter()) {
                intersectionGrid[x][y] = BNAFILTEREDCOLOR;
              }
            }
            break;
          case 2:
            if (overlayNoiseSize <= 0
                || hasNeighbour(x, y, xx, yy, left, top, pixelType) > overlayNoiseSize) {
              tmpPixelAButNotB++;
              if (isCreateIntersectionLetter()) {
                intersectionGrid[x][y] = ANBCOLOR;
              }
            } else {

              if (isCreateIntersectionLetter()) {
                intersectionGrid[x][y] = ANBFILTEREDCOLOR;
              }
            }
            break;
          default:
            if (isCreateIntersectionLetter()) {
              intersectionGrid[x][y] = 0xffffff;
            }
        }
      }
    }

    // logger.info("Scanner: "+Utilities.getTimer(starter));
    // if(getDecodedValue().equalsIgnoreCase("v")&&getBothElementsNum()==3){
    // logger.info("JJJ");
    // }
    if (pixelAll > 0 && (bothElements.size() > 0 || cleftFaktor == 0)) {
      tmpErrorA = (double) tmpPixelAButNotB / (double) (tmpPixelBoth + tmpPixelAButNotB);
      tmpErrorB = (double) tmpPixelBButNotA / (double) (tmpPixelBButNotA + tmpPixelBoth);
      tmpErrorTotal = tmpErrorA * errorAWeight + tmpErrorB * errorbWeight;

      tmpCoverageFaktorA =
          1.0 - tmpPixelBoth / ((double) a.getElementPixel() / (scanStepX * scanStepY));
      tmpCoverageFaktorB =
          1.0 - tmpPixelBoth / ((double) b.getElementPixel() / (scanStepX * scanStepY));
      setLocalHeightPercent((double) tmpIntersectionHeight / (double) b.getHeight());
      localWidthPercent = (double) tmpIntersectionWidth / (double) b.getWidth();
      double lhp = 1.0 - getLocalHeightPercent();
      double lwp = 1.0 - localWidthPercent;
      tmpHeightFaktor = lhp * lhp;
      tmpWidthFaktor = lwp * lwp;
      tmpHeightAFaktor = 1.0 - (double) tmpIntersectionHeight / (double) a.getHeight();
      tmpWidthAFaktor = 1.0 - (double) tmpIntersectionWidth / (double) a.getWidth();
      // logger.info(tmpIntersectionWidth+ "/"+a.getWidth()+" =
      // "+localWidthPercent+" --> "+tmpWidthFaktor);

      tmpError = tmpErrorTotal;
      tmpError += Math.min(1.0, tmpCoverageFaktorA) * coverageFaktorAWeight;
      tmpError += Math.min(1.0, tmpCoverageFaktorB) * coverageFaktorBWeight;
      tmpError += Math.min(1.0, tmpHeightFaktor) * intersectionDimensionWeight;
      tmpError += Math.min(1.0, tmpWidthFaktor) * intersectionDimensionWeight;
      tmpError += Math.min(1.0, tmpHeightAFaktor) * intersectionAHeightWeight;
      tmpError += Math.min(1.0, tmpWidthAFaktor) * intersectionAWidthWeight;
      if (bothElements.size() > 0) {
        tmpError += (bothElements.size() - 1) * cleftFaktor;
      }

      tmpExtensionError = 0.0;
      if (extensionCodeMethod != null) {
        try {
          extensionCodeArguments[1] = tmpError / divider;
          extensionCodeMethod.invoke(null, extensionCodeArguments);
        } catch (Exception e) {
          JDLogger.exception(e);
        }
      }

      tmpError += tmpExtensionError;
      tmpError /= divider;
      // tmpError = Math.min(1.0, tmpError);
      // logger.info(pixelBoth+"_"+(tmpIntersectionHeight *
      // tmpIntersectionWidth));
      if (tmpPixelBoth * owner.getJas().getDouble("inverseFontWeight")
          < tmpIntersectionHeight * tmpIntersectionWidth) {
        tmpError = tmpErrorA = tmpErrorB = tmpErrorTotal = 10000.0 / 100.0;
      }

      return 100.0 * tmpError;
    } else {

      return 10000.0;
    }
  }