Java 类com.google.zxing.LuminanceSource 实例源码

项目:IJPay    文件:ZxingKit.java   
/**
 * @param srcImgFilePath
 *            要解码的图片地址
 * @return {Result}
 */
@SuppressWarnings("finally")
public static Result decode(String srcImgFilePath) {
    Result result = null;
    BufferedImage image;
    try {
        File srcFile = new File(srcImgFilePath);
        image = ImageIO.read(srcFile);
        if (null != image) {
            LuminanceSource source = new BufferedImageLuminanceSource(image);
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

            Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
            hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
            result = new MultiFormatReader().decode(bitmap, hints);
        } else {
            throw new IllegalArgumentException ("Could not decode image.");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        return result;
    }
}
项目:framework    文件:BarCodeUtils.java   
/**
 * 条形码解码
 */
public static String decode(BufferedImage image) {
    Result result = null;
    try {
        if (image == null) {
            System.out.println("the decode image may be not exit.");
        }
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        result = new MultiFormatReader().decode(bitmap, null);
        return result.getText();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:qrcode-utils    文件:BufferedImageLuminanceSource.java   
@Override
public LuminanceSource rotateCounterClockwise() {

  int sourceWidth = this.image.getWidth();
  int sourceHeight = this.image.getHeight();

  AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0,
    0.0, sourceWidth);

  BufferedImage rotatedImage = new BufferedImage(sourceHeight,
    sourceWidth, BufferedImage.TYPE_BYTE_GRAY);

  Graphics2D g = rotatedImage.createGraphics();
  g.drawImage(this.image, transform, null);
  g.dispose();

  int width = getWidth();
  return new BufferedImageLuminanceSource(rotatedImage, this.top,
    sourceWidth - (this.left + width), getHeight(), width);
}
项目:iBase4J-Common    文件:QrcodeUtil.java   
public static String decodeQr(String filePath) {
    String retStr = "";
    if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
        return "图片路径为空!";
    }
    try {
        BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
        LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
        Binarizer binarizer = new HybridBinarizer(source);
        BinaryBitmap bitmap = new BinaryBitmap(binarizer);
        HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
        hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
        Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
        retStr = result.getText();
    } catch (Exception e) {
        logger.error("", e);
    }
    return retStr;
}
项目:automat    文件:QrcodeUtil.java   
public static String decodeQr(String filePath) {
    String retStr = "";
    if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
        return "图片路径为空!";
    }
    try {
        BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
        LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
        Binarizer binarizer = new HybridBinarizer(source);
        BinaryBitmap bitmap = new BinaryBitmap(binarizer);
        HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
        hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
        Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
        retStr = result.getText();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return retStr;
}
项目:Fetax-AI    文件:CodeUtil.java   
/**
* 解析条形码
*/
  public static String decodes(String imgPath) {
      BufferedImage image = null;
      Result result = null;
      try {
          image = ImageIO.read(new File(imgPath));
          if (image == null) {
              System.out.println("the decode image may be not exit.");
          }
          LuminanceSource source = new BufferedImageLuminanceSource(image);
          BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

          result = new MultiFormatReader().decode(bitmap, null);
          return result.getText();
      } catch (Exception e) {
          e.printStackTrace();
      }
      return null;
  }
项目:JAVA-    文件:QrcodeUtil.java   
public static String decodeQr(String filePath) {
    String retStr = "";
    if ("".equalsIgnoreCase(filePath) && filePath.length() == 0) {
        return "图片路径为空!";
    }
    try {
        BufferedImage bufferedImage = ImageIO.read(new FileInputStream(filePath));
        LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
        Binarizer binarizer = new HybridBinarizer(source);
        BinaryBitmap bitmap = new BinaryBitmap(binarizer);
        HashMap<DecodeHintType, Object> hintTypeObjectHashMap = new HashMap<>();
        hintTypeObjectHashMap.put(DecodeHintType.CHARACTER_SET, "UTF-8");
        Result result = new MultiFormatReader().decode(bitmap, hintTypeObjectHashMap);
        retStr = result.getText();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return retStr;
}
项目:angit    文件:ZxingHelper.java   
/**
 * 条形码解码
 *
 * @param imgPath 文件路径
 * @return String string
 */
public static String decode(String imgPath) {
    BufferedImage image;
    Result result;
    try {
        image = ImageIO.read(new File(imgPath));
        if (image == null) {
            LOGGER.error("the decode image may be not exit.");
            return null;
        }
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        result = new MultiFormatReader().decode(bitmap, null);
        return result.getText();
    } catch (Exception e) {
        LOGGER.error("条形码解析错误", e);
    }
    return null;
}
项目:angit    文件:ZxingHelper.java   
/**
 * 二维码解码
 *
 * @param imgPath 文件路径
 * @return String string
 */
public static String decode2(String imgPath) {
    BufferedImage image;
    Result result;
    try {
        image = ImageIO.read(new File(imgPath));
        if (image == null) {
            LOGGER.error("the decode image may be not exit.");
            return null;
        }
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        EnumMap<DecodeHintType, Object> hints = new EnumMap<>(DecodeHintType.class);
        hints.put(DecodeHintType.CHARACTER_SET, "GBK");

        result = new MultiFormatReader().decode(bitmap, hints);
        return result.getText();
    } catch (Exception e) {
        LOGGER.error("二维码解码错误", e);
    }
    return null;
}
项目:awe-awesomesky    文件:CodeUtil.java   
/**
* 解析条形码
*/
  public static String decodes(String imgPath) {
      BufferedImage image = null;
      Result result = null;
      try {
          image = ImageIO.read(new File(imgPath));
          if (image == null) {
              System.out.println("the decode image may be not exit.");
          }
          LuminanceSource source = new BufferedImageLuminanceSource(image);
          BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

          result = new MultiFormatReader().decode(bitmap, null);
          return result.getText();
      } catch (Exception e) {
          e.printStackTrace();
      }
      return null;
  }
项目:simbest-cores    文件:QrCodeUtil.java   
/**
 * 读取二维码
 * @param qrCodeFile
 * @return
 */
public String readQrCode(File qrCodeFile){
    String ret = null;
    try {           
        QRCodeReader reader = new QRCodeReader();
        BufferedImage image = ImageIO.read(qrCodeFile);
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        Binarizer binarizer = new HybridBinarizer(source);
        BinaryBitmap imageBinaryBitmap = new BinaryBitmap(binarizer);
        Result result = reader.decode(imageBinaryBitmap);
        ret = result.getText();
    } catch (IOException |NotFoundException | ChecksumException | FormatException e) {
        Exceptions.printException(e);
    }
    return ret;     
}
项目:Shop-for-JavaWeb    文件:ZxingHandler.java   
/**
 * 条形码解码
 * 
 * @param imgPath
 * @return String
 */
public static String decode(String imgPath) {
    BufferedImage image = null;
    Result result = null;
    try {
        image = ImageIO.read(new File(imgPath));
        if (image == null) {
            System.out.println("the decode image may be not exit.");
        }
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        result = new MultiFormatReader().decode(bitmap, null);
        return result.getText();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:Shop-for-JavaWeb    文件:ZxingHandler.java   
/**
 * 二维码解码
 * 
 * @param imgPath
 * @return String
 */
public static String decode2(String imgPath) {
    BufferedImage image = null;
    Result result = null;
    try {
        image = ImageIO.read(new File(imgPath));
        if (image == null) {
            System.out.println("the decode image may be not exit.");
        }
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.CHARACTER_SET, "GBK");

        result = new MultiFormatReader().decode(bitmap, hints);
        return result.getText();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
项目:qr-code-reader    文件:QRDecoder.java   
/**
 * Decodes a QR code from a BufferedImage object.
 * 
 * @param image
 * @return a Result object containing the decoded data or information about
 *         an unsuccessful decoding attempt
 * @throws Exception
 */
private Result decode(BufferedImage image) throws Exception {

    // create a luminance source from the BufferedImage
    LuminanceSource lumSource = new BufferedImageLuminanceSource(image);
    // create a binary bitmap from the luminance source. a Binarizer
    // converts luminance data to 1 bit data.
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(lumSource));

    // a reader for decoding
    QRCodeReader reader = new QRCodeReader();

    // attempt decoding and return result
    Hashtable<DecodeHintType, Boolean> hints = new Hashtable<DecodeHintType, Boolean>();
    hints.put(DecodeHintType.TRY_HARDER, true);
    return reader.decode(bitmap, hints);
}
项目:qrcode-desktop    文件:BufferedImageLuminanceSource.java   
@Override
public LuminanceSource rotateCounterClockwise() {
  //if (!isRotateSupported()) {
  //  throw new IllegalStateException("Rotate not supported");
  //}
  int sourceWidth = image.getWidth();
  int sourceHeight = image.getHeight();

  // Rotate 90 degrees counterclockwise.
  AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth);

  // Note width/height are flipped since we are rotating 90 degrees.
  BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY);

  // Draw the original image into rotated, via transformation
  Graphics2D g = rotatedImage.createGraphics();
  g.drawImage(image, transform, null);
  g.dispose();

  // Maintain the cropped region, but rotate it too.
  int width = getWidth();
  return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width);
}
项目:RipplePower    文件:BufferedImageLuminanceSource.java   
@Override
public LuminanceSource rotateCounterClockwise() {
    int sourceWidth = image.getWidth();
    int sourceHeight = image.getHeight();

    // Rotate 90 degrees counterclockwise.
    AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0, 0.0, 0.0, sourceWidth);

    // Note width/height are flipped since we are rotating 90 degrees.
    BufferedImage rotatedImage = new BufferedImage(sourceHeight, sourceWidth, BufferedImage.TYPE_BYTE_GRAY);

    // Draw the original image into rotated, via transformation
    Graphics2D g = rotatedImage.createGraphics();
    g.drawImage(image, transform, null);
    g.dispose();

    // Maintain the cropped region, but rotate it too.
    int width = getWidth();
    return new BufferedImageLuminanceSource(rotatedImage, top, sourceWidth - (left + width), getHeight(), width);
}
项目:Simplicissimus    文件:HybridBinarizer.java   
private void binarizeEntireImage() throws NotFoundException {
  if (matrix == null) {
    LuminanceSource source = getLuminanceSource();
    if (source.getWidth() >= MINIMUM_DIMENSION && source.getHeight() >= MINIMUM_DIMENSION) {
      byte[] luminances = source.getMatrix();
      int width = source.getWidth();
      int height = source.getHeight();
      int subWidth = width >> 3;
      if ((width & 0x07) != 0) {
        subWidth++;
      }
      int subHeight = height >> 3;
      if ((height & 0x07) != 0) {
        subHeight++;
      }
      int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height);

      matrix = new BitMatrix(width, height);
      calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, matrix);
    } else {
      // If the image is too small, fall back to the global histogram approach.
      matrix = super.getBlackMatrix();
    }
  }
}
项目:zxing-bsplus    文件:MultiTestCase.java   
@Ignore
public void testMulti() throws Exception {
  // Very basic test for now
  Path testBase = AbstractBlackBoxTestCase.buildTestBase("src/test/resources/blackbox/multi-1");

  Path testImage = testBase.resolve("1.png");
  BufferedImage image = ImageIO.read(testImage.toFile());
  LuminanceSource source = new BufferedImageLuminanceSource(image);
  BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

  MultipleBarcodeReader reader = new GenericMultipleBarcodeReader(new MultiFormatReader());
  Result[] results = reader.decodeMultiple(bitmap);
  assertNotNull(results);
  assertEquals(2, results.length);

  assertEquals("031415926531", results[0].getText());
  assertEquals(BarcodeFormat.UPC_A, results[0].getBarcodeFormat());

  assertEquals("www.airtable.com/jobs", results[1].getText());
  assertEquals(BarcodeFormat.QR_CODE, results[1].getBarcodeFormat());
}
项目:Android-Barcode-Reader    文件:CameraPreview.java   
@Override
     public void onPreviewFrame(byte[] data, Camera camera) {
         // TODO Auto-generated method stub

        if (mDialog.isShowing())
            return;

        LuminanceSource source = new PlanarYUVLuminanceSource(data, mWidth, mHeight, mLeft, mTop, mAreaWidth, mAreaHeight, false);
         BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(
           source));
         Result result;

         try {
    result = mMultiFormatReader.decode(bitmap, null);
    if (result != null) {
        mDialog.setTitle("Result");
        mDialog.setMessage(result.getText());
        mDialog.show();
    }
} catch (NotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
     }
项目:StreamingQR    文件:ReceiveTest.java   
/**
 * Try decoding standard QR code without any of the
 * sequence information inserted into payload.
 */
@Test
public void testDecodeQrWithNoSequenceInfo() {
  // Decode qr code received from transmitter as screenshot
  String filename = "fooScreenshot_noReservedBits.png";
  String expectedText   = "foo";

  BufferedImage b = getImageResourceAndCheckNotNull(filename);
  LuminanceSource lumSrc = new BufferedImageLuminanceSource(b);

  assertNotNull("Unable to convert BufferedImage to LuminanceSrc", lumSrc);
  try {
    Result result = Receive.decodeSingle(lumSrc);
    assertEquals("Expect decoded result to match expected", expectedText, result.getText());
  } catch (NotFoundException e) {
    fail("Unable to find QR in image, "+filename + ". " + e.getMessage());
  }
}
项目:StreamingQR    文件:ReceiveTest.java   
private Iterable<Result> decodeMultipleAndCheckValidQR(LuminanceSource img, String filename) {
  Iterable<Result> results = null;
  try {
    results = Receive.decodeMultiple(img);

    assertNotNull("QR result should not be null", results);
    Iterator<Result> resIter = results.iterator();
    assertTrue("QR has at least one result", resIter.hasNext());
  } catch (NotFoundException e) {
    if (filename != null) {
      fail("Unable to find QR in image, " + filename +". "+ e.getMessage());
    }else{
      fail("Unable to find QR in image. " + e.getMessage());
    }
  }
  return results;
}
项目:StreamingQR    文件:ReceiveTest.java   
@Test
public void testDecodeTwoQRCodesSameImage() throws ReceiveException {

  String expectAll = "qr_4Of4.png";

  // Use receive to decode this qr code:
  Receive receive = new Receive(0, 0, NULL_MONITOR);

  // The received data and track transmission status.
  DecodedMessage message = new DecodedMessage(NULL_MONITOR);

  LuminanceSource img = getLuminanceImgAndCheckNotNull(expectAll);
  Iterable <Result> results = decodeMultipleAndCheckValidQR(img,expectAll);
  State s = receive.saveMessageAndUpdateProgress(results, message);

  assertTrue("Expected to be in Final state.", s == State.Final);
  System.out.println("MESSAGE=" + message.toString());
}
项目:sparkbit    文件:QRCodeEncoderDecoder.java   
public String decode(BufferedImage image) {

        // convert the image to a binary bitmap source
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

        // decode the barcode
        QRCodeReader reader = new QRCodeReader();

        try {
            @SuppressWarnings("rawtypes")
            Hashtable hints = new Hashtable();
            Result result = reader.decode(bitmap, hints);
            log.info("Decoded image successfully, result was : '" + result.getText() + "'");

            return result.getText();
        } catch (ReaderException e) {
            // the data is improperly formatted
            log.debug(e.getMessage());
            log.error("Error while decoding image", e);
        }

        return "";
    }
项目:weex-3d-map    文件:GlobalHistogramBinarizer.java   
@Override
public BitArray getBlackRow(int y, BitArray row) throws NotFoundException {
  LuminanceSource source = getLuminanceSource();
  int width = source.getWidth();
  if (row == null || row.getSize() < width) {
    row = new BitArray(width);
  } else {
    row.clear();
  }

  initArrays(width);
  byte[] localLuminances = source.getRow(y, luminances);
  int[] localBuckets = buckets;
  for (int x = 0; x < width; x++) {
    int pixel = localLuminances[x] & 0xff;
    localBuckets[pixel >> LUMINANCE_SHIFT]++;
  }
  int blackPoint = estimateBlackPoint(localBuckets);

  int left = localLuminances[0] & 0xff;
  int center = localLuminances[1] & 0xff;
  for (int x = 1; x < width - 1; x++) {
    int right = localLuminances[x + 1] & 0xff;
    // A simple -1 4 -1 box filter with a weight of 2.
    int luminance = ((center * 4) - left - right) / 2;
    if (luminance < blackPoint) {
      row.set(x);
    }
    left = center;
    center = right;
  }
  return row;
}
项目:weex-3d-map    文件:HybridBinarizer.java   
/**
 * Calculates the final BitMatrix once for all requests. This could be called once from the
 * constructor instead, but there are some advantages to doing it lazily, such as making
 * profiling easier, and not doing heavy lifting when callers don't expect it.
 */
@Override
public BitMatrix getBlackMatrix() throws NotFoundException {
  if (matrix != null) {
    return matrix;
  }
  LuminanceSource source = getLuminanceSource();
  int width = source.getWidth();
  int height = source.getHeight();
  if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) {
    byte[] luminances = source.getMatrix();
    int subWidth = width >> BLOCK_SIZE_POWER;
    if ((width & BLOCK_SIZE_MASK) != 0) {
      subWidth++;
    }
    int subHeight = height >> BLOCK_SIZE_POWER;
    if ((height & BLOCK_SIZE_MASK) != 0) {
      subHeight++;
    }
    int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height);

    BitMatrix newMatrix = new BitMatrix(width, height);
    calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix);
    matrix = newMatrix;
  } else {
    // If the image is too small, fall back to the global histogram approach.
    matrix = super.getBlackMatrix();
  }
  return matrix;
}
项目:ZxingForAndroid    文件:DecoderThread.java   
protected LuminanceSource createSource(SourceData sourceData) {
    if (this.cropRect == null) {
        return null;
    } else {
        return sourceData.createSource();
    }
}
项目:QrCode    文件:GlobalHistogramBinarizer.java   
@Override
public BitArray getBlackRow(int y, BitArray row) throws NotFoundException {
  LuminanceSource source = getLuminanceSource();
  int width = source.getWidth();
  if (row == null || row.getSize() < width) {
    row = new BitArray(width);
  } else {
    row.clear();
  }

  initArrays(width);
  byte[] localLuminances = source.getRow(y, luminances);
  int[] localBuckets = buckets;
  for (int x = 0; x < width; x++) {
    localBuckets[(localLuminances[x] & 0xff) >> LUMINANCE_SHIFT]++;
  }
  int blackPoint = estimateBlackPoint(localBuckets);

  if (width < 3) {
    // Special case for very small images
    for (int x = 0; x < width; x++) {
      if ((localLuminances[x] & 0xff) < blackPoint) {
        row.set(x);
      }
    }
  } else {
    int left = localLuminances[0] & 0xff;
    int center = localLuminances[1] & 0xff;
    for (int x = 1; x < width - 1; x++) {
      int right = localLuminances[x + 1] & 0xff;
      // A simple -1 4 -1 box filter with a weight of 2.
      if (((center * 4) - left - right) / 2 < blackPoint) {
        row.set(x);
      }
      left = center;
      center = right;
    }
  }
  return row;
}
项目:QrCode    文件:HybridBinarizer.java   
/**
 * Calculates the final BitMatrix once for all requests. This could be called once from the
 * constructor instead, but there are some advantages to doing it lazily, such as making
 * profiling easier, and not doing heavy lifting when callers don't expect it.
 */
@Override
public BitMatrix getBlackMatrix() throws NotFoundException {
  if (matrix != null) {
    return matrix;
  }
  LuminanceSource source = getLuminanceSource();
  int width = source.getWidth();
  int height = source.getHeight();
  if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) {
    byte[] luminances = source.getMatrix();
    int subWidth = width >> BLOCK_SIZE_POWER;
    if ((width & BLOCK_SIZE_MASK) != 0) {
      subWidth++;
    }
    int subHeight = height >> BLOCK_SIZE_POWER;
    if ((height & BLOCK_SIZE_MASK) != 0) {
      subHeight++;
    }
    int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height);

    BitMatrix newMatrix = new BitMatrix(width, height);
    calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix);
    matrix = newMatrix;
  } else {
    // If the image is too small, fall back to the global histogram approach.
    matrix = super.getBlackMatrix();
  }
  return matrix;
}
项目:Fetax-AI    文件:CodeImage.java   
public LuminanceSource rotateCounterClockwise() {
    int sourceWidth = image.getWidth();
    int sourceHeight = image.getHeight();
    AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0,
            0.0, 0.0, sourceWidth);
    BufferedImage rotatedImage = new BufferedImage(sourceHeight,
            sourceWidth, BufferedImage.TYPE_BYTE_GRAY);
    Graphics2D g = rotatedImage.createGraphics();
    g.drawImage(image, transform, null);
    g.dispose();
    int width = getWidth();
    return new CodeImage(rotatedImage, top,
            sourceWidth - (left + width), getHeight(), width);
}
项目:bicycleSharingServer    文件:BufferedImageLuminanceSource.java   
public LuminanceSource rotateCounterClockwise() {
    int sourceWidth = image.getWidth();
    int sourceHeight = image.getHeight();
    AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0,
            0.0, 0.0, sourceWidth);
    BufferedImage rotatedImage = new BufferedImage(sourceHeight,
            sourceWidth, BufferedImage.TYPE_BYTE_GRAY);
    Graphics2D g = rotatedImage.createGraphics();
    g.drawImage(image, transform, null);
    g.dispose();
    int width = getWidth();
    return new BufferedImageLuminanceSource(rotatedImage, top,
            sourceWidth - (left + width), getHeight(), width);
}
项目:boohee_v5.6    文件:GlobalHistogramBinarizer.java   
public BitArray getBlackRow(int y, BitArray row) throws NotFoundException {
    int x;
    LuminanceSource source = getLuminanceSource();
    int width = source.getWidth();
    if (row == null || row.getSize() < width) {
        row = new BitArray(width);
    } else {
        row.clear();
    }
    initArrays(width);
    byte[] localLuminances = source.getRow(y, this.luminances);
    int[] localBuckets = this.buckets;
    for (x = 0; x < width; x++) {
        int i = (localLuminances[x] & 255) >> 3;
        localBuckets[i] = localBuckets[i] + 1;
    }
    int blackPoint = estimateBlackPoint(localBuckets);
    int left = localLuminances[0] & 255;
    int center = localLuminances[1] & 255;
    for (x = 1; x < width - 1; x++) {
        int right = localLuminances[x + 1] & 255;
        if ((((center * 4) - left) - right) / 2 < blackPoint) {
            row.set(x);
        }
        left = center;
        center = right;
    }
    return row;
}
项目:boohee_v5.6    文件:GlobalHistogramBinarizer.java   
public BitMatrix getBlackMatrix() throws NotFoundException {
    int y;
    byte[] localLuminances;
    LuminanceSource source = getLuminanceSource();
    int width = source.getWidth();
    int height = source.getHeight();
    BitMatrix matrix = new BitMatrix(width, height);
    initArrays(width);
    int[] localBuckets = this.buckets;
    for (y = 1; y < 5; y++) {
        int x;
        localLuminances = source.getRow((height * y) / 5, this.luminances);
        int right = (width * 4) / 5;
        for (x = width / 5; x < right; x++) {
            int i = (localLuminances[x] & 255) >> 3;
            localBuckets[i] = localBuckets[i] + 1;
        }
    }
    int blackPoint = estimateBlackPoint(localBuckets);
    localLuminances = source.getMatrix();
    for (y = 0; y < height; y++) {
        int offset = y * width;
        for (x = 0; x < width; x++) {
            if ((localLuminances[offset + x] & 255) < blackPoint) {
                matrix.set(x, y);
            }
        }
    }
    return matrix;
}
项目:boohee_v5.6    文件:HybridBinarizer.java   
public BitMatrix getBlackMatrix() throws NotFoundException {
    if (this.matrix != null) {
        return this.matrix;
    }
    LuminanceSource source = getLuminanceSource();
    int width = source.getWidth();
    int height = source.getHeight();
    if (width < 40 || height < 40) {
        this.matrix = super.getBlackMatrix();
    } else {
        byte[] luminances = source.getMatrix();
        int subWidth = width >> 3;
        if ((width & 7) != 0) {
            subWidth++;
        }
        int subHeight = height >> 3;
        if ((height & 7) != 0) {
            subHeight++;
        }
        int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width,
                height);
        BitMatrix newMatrix = new BitMatrix(width, height);
        calculateThresholdForBlock(luminances, subWidth, subHeight, width, height,
                blackPoints, newMatrix);
        this.matrix = newMatrix;
    }
    return this.matrix;
}
项目:appinventor-extensions    文件:DecodeHandler.java   
private static Bitmap toBitmap(LuminanceSource source, int[] pixels) {
  int width = source.getWidth();
  int height = source.getHeight();
  Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
  bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
  return bitmap;
}
项目:Tesseract-OCR-Scanner    文件:GlobalHistogramBinarizer.java   
@Override
public BitArray getBlackRow(int y, BitArray row) throws NotFoundException {
  LuminanceSource source = getLuminanceSource();
  int width = source.getWidth();
  if (row == null || row.getSize() < width) {
    row = new BitArray(width);
  } else {
    row.clear();
  }

  initArrays(width);
  byte[] localLuminances = source.getRow(y, luminances);
  int[] localBuckets = buckets;
  for (int x = 0; x < width; x++) {
    localBuckets[(localLuminances[x] & 0xff) >> LUMINANCE_SHIFT]++;
  }
  int blackPoint = estimateBlackPoint(localBuckets);

  if (width < 3) {
    // Special case for very small images
    for (int x = 0; x < width; x++) {
      if ((localLuminances[x] & 0xff) < blackPoint) {
        row.set(x);
      }
    }
  } else {
    int left = localLuminances[0] & 0xff;
    int center = localLuminances[1] & 0xff;
    for (int x = 1; x < width - 1; x++) {
      int right = localLuminances[x + 1] & 0xff;
      // A simple -1 4 -1 box filter with a weight of 2.
      if (((center * 4) - left - right) / 2 < blackPoint) {
        row.set(x);
      }
      left = center;
      center = right;
    }
  }
  return row;
}
项目:Tesseract-OCR-Scanner    文件:HybridBinarizer.java   
/**
 * Calculates the final BitMatrix once for all requests. This could be called once from the
 * constructor instead, but there are some advantages to doing it lazily, such as making
 * profiling easier, and not doing heavy lifting when callers don't expect it.
 */
@Override
public BitMatrix getBlackMatrix() throws NotFoundException {
  if (matrix != null) {
    return matrix;
  }
  LuminanceSource source = getLuminanceSource();
  int width = source.getWidth();
  int height = source.getHeight();
  if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) {
    byte[] luminances = source.getMatrix();
    int subWidth = width >> BLOCK_SIZE_POWER;
    if ((width & BLOCK_SIZE_MASK) != 0) {
      subWidth++;
    }
    int subHeight = height >> BLOCK_SIZE_POWER;
    if ((height & BLOCK_SIZE_MASK) != 0) {
      subHeight++;
    }
    int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height);

    BitMatrix newMatrix = new BitMatrix(width, height);
    calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix);
    matrix = newMatrix;
  } else {
    // If the image is too small, fall back to the global histogram approach.
    matrix = super.getBlackMatrix();
  }
  return matrix;
}
项目:QRCodeScanner    文件:DecodeManger.java   
private Result decode(LuminanceSource source) {
    Result rawResult = null;
    if (source != null) {
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        try {
            rawResult = multiFormatReader.decodeWithState(bitmap);
        } catch (ReaderException re) {
            //continue
        } finally {
            multiFormatReader.reset();
        }
    }
    return rawResult;
}
项目:awe-awesomesky    文件:CodeImage.java   
public LuminanceSource rotateCounterClockwise() {
    int sourceWidth = image.getWidth();
    int sourceHeight = image.getHeight();
    AffineTransform transform = new AffineTransform(0.0, -1.0, 1.0,
            0.0, 0.0, sourceWidth);
    BufferedImage rotatedImage = new BufferedImage(sourceHeight,
            sourceWidth, BufferedImage.TYPE_BYTE_GRAY);
    Graphics2D g = rotatedImage.createGraphics();
    g.drawImage(image, transform, null);
    g.dispose();
    int width = getWidth();
    return new CodeImage(rotatedImage, top,
            sourceWidth - (left + width), getHeight(), width);
}
项目:QrCodeScanner    文件:GlobalHistogramBinarizer.java   
@Override
public BitArray getBlackRow(int y, BitArray row) throws NotFoundException {
  LuminanceSource source = getLuminanceSource();
  int width = source.getWidth();
  if (row == null || row.getSize() < width) {
    row = new BitArray(width);
  } else {
    row.clear();
  }

  initArrays(width);
  byte[] localLuminances = source.getRow(y, luminances);
  int[] localBuckets = buckets;
  for (int x = 0; x < width; x++) {
    localBuckets[(localLuminances[x] & 0xff) >> LUMINANCE_SHIFT]++;
  }
  int blackPoint = estimateBlackPoint(localBuckets);

  if (width < 3) {
    // Special case for very small images
    for (int x = 0; x < width; x++) {
      if ((localLuminances[x] & 0xff) < blackPoint) {
        row.set(x);
      }
    }
  } else {
    int left = localLuminances[0] & 0xff;
    int center = localLuminances[1] & 0xff;
    for (int x = 1; x < width - 1; x++) {
      int right = localLuminances[x + 1] & 0xff;
      // A simple -1 4 -1 box filter with a weight of 2.
      if (((center * 4) - left - right) / 2 < blackPoint) {
        row.set(x);
      }
      left = center;
      center = right;
    }
  }
  return row;
}
项目:QrCodeScanner    文件:HybridBinarizer.java   
/**
 * Calculates the final BitMatrix once for all requests. This could be called once from the
 * constructor instead, but there are some advantages to doing it lazily, such as making
 * profiling easier, and not doing heavy lifting when callers don't expect it.
 */
@Override
public BitMatrix getBlackMatrix() throws NotFoundException {
  if (matrix != null) {
    return matrix;
  }
  LuminanceSource source = getLuminanceSource();
  int width = source.getWidth();
  int height = source.getHeight();
  if (width >= MINIMUM_DIMENSION && height >= MINIMUM_DIMENSION) {
    byte[] luminances = source.getMatrix();
    int subWidth = width >> BLOCK_SIZE_POWER;
    if ((width & BLOCK_SIZE_MASK) != 0) {
      subWidth++;
    }
    int subHeight = height >> BLOCK_SIZE_POWER;
    if ((height & BLOCK_SIZE_MASK) != 0) {
      subHeight++;
    }
    int[][] blackPoints = calculateBlackPoints(luminances, subWidth, subHeight, width, height);

    BitMatrix newMatrix = new BitMatrix(width, height);
    calculateThresholdForBlock(luminances, subWidth, subHeight, width, height, blackPoints, newMatrix);
    matrix = newMatrix;
  } else {
    // If the image is too small, fall back to the global histogram approach.
    matrix = super.getBlackMatrix();
  }
  return matrix;
}