コード例 #1
0
 /** A wrapper for {@link #setImage(int, int, ByteBuffer, Rectangle, int)}. */
 private void setImage(RenderedImage image, Rectangle rect) throws IOException {
   setImage(
       image.getWidth(),
       image.getHeight(),
       ImageIOHelper.getImageByteBuffer(image),
       rect,
       image.getColorModel().getPixelSize());
 }
コード例 #2
0
 /**
  * Performs OCR operation.
  *
  * @param bi a buffered image
  * @param rect the bounding rectangle defines the region of the image to be recognized. A
  *     rectangle of zero dimension or <code>null</code> indicates the whole image.
  * @return the recognized text
  * @throws TesseractException
  */
 public String doOCR(BufferedImage bi, Rectangle rect) throws TesseractException {
   try {
     return doOCR(ImageIOHelper.getIIOImageList(bi), rect);
   } catch (Exception e) {
     logger.log(Level.SEVERE, e.getMessage(), e);
     throw new TesseractException(e);
   }
 }
コード例 #3
0
ファイル: OCRImageEntity.java プロジェクト: ADTC/VietOCR
 /**
  * Gets cloned image files.
  *
  * @return the ClonedImageFiles
  * @throws java.io.IOException
  */
 public List<File> getClonedImageFiles() throws IOException {
   if (oimages != null) {
     if (dpiX == 0 || dpiY == 0) {
       if (rect == null || rect.isEmpty()) {
         return ImageIOHelper.createTiffFiles(oimages, index);
       } else {
         // rectangular region
         //                    BufferedImage bi = ((BufferedImage)
         // oimages.get(index).getRenderedImage()).getSubimage(rect.x, rect.y, rect.width,
         // rect.height);
         // On Linux, the standard getSubimage method has generated images that Tesseract does not
         // like.
         BufferedImage bi =
             ImageHelper.getSubImage(
                 (BufferedImage) oimages.get(index).getRenderedImage(),
                 rect.x,
                 rect.y,
                 rect.width,
                 rect.height);
         List<IIOImage> tempList = new ArrayList<IIOImage>();
         tempList.add(new IIOImage(bi, null, null));
         return ImageIOHelper.createTiffFiles(tempList, 0);
       }
     } else {
       // scaling
       if (rect == null || rect.isEmpty()) {
         List<IIOImage> tempList = new ArrayList<IIOImage>();
         for (IIOImage oimage : (index == -1 ? oimages : oimages.subList(index, index + 1))) {
           BufferedImage bi = (BufferedImage) oimage.getRenderedImage();
           Map<String, String> metadata = ImageIOHelper.readImageData(oimage);
           float scale = dpiX / Float.parseFloat(metadata.get("dpiX"));
           bi =
               ImageHelper.getScaledInstance(
                   bi, (int) (bi.getWidth() * scale), (int) (bi.getHeight() * scale));
           tempList.add(new IIOImage(bi, null, null));
         }
         return ImageIOHelper.createTiffFiles(tempList, (index == -1 ? index : 0), dpiX, dpiY);
       } else {
         // rectangular region
         // Cut out the subimage first and rescale that
         BufferedImage bi =
             ((BufferedImage) oimages.get(index).getRenderedImage())
                 .getSubimage(rect.x, rect.y, rect.width, rect.height);
         Map<String, String> metadata = ImageIOHelper.readImageData(oimages.get(index));
         float scale = dpiX / Float.parseFloat(metadata.get("dpiX"));
         bi =
             ImageHelper.getScaledInstance(
                 bi, (int) (bi.getWidth() * scale), (int) (bi.getHeight() * scale));
         List<IIOImage> tempList = new ArrayList<IIOImage>();
         tempList.add(new IIOImage(bi, null, null));
         return ImageIOHelper.createTiffFiles(tempList, 0, dpiX, dpiY);
       }
     }
   } else {
     return ImageIOHelper.createTiffFiles(imageFile, index);
   }
 }