Exemplo n.º 1
0
  // Used to get text in a image store at the location specified by the path
  public static String getText(String path) {
    // read a low quality image to save memory
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;
    try {

      Bitmap temp_bitmap = BitmapFactory.decodeFile(path, options);
      ExifInterface exif = new ExifInterface(path);

      // Correct the orientation of the bitmap
      temp_bitmap = ImageProcessor.correctOrientation(temp_bitmap, exif);
      Bitmap bitmap = ImageProcessor.optimizeBitmap(temp_bitmap);

      String recognizedText = BookSearchApp.scanPhoto(bitmap);

      // remove some wrong results
      if (BookSearchApp.lang.equalsIgnoreCase("eng")) {
        recognizedText = recognizedText.replaceAll("[^a-zA-Z0-9]+", "");
      }

      recognizedText = recognizedText.trim();
      return recognizedText;

    } catch (IOException e) {
      // if there is a error with the SD card
      Log.d(TAG, "Error reading from SD Card");
      e.printStackTrace();
    }
    return "";
  }