【发布时间】:2015-06-03 13:17:44
【问题描述】:
我正在尝试在 Visual Studio(适用于 Android)上将 Tesseract OCR 与 cordova 一起使用。使用 Cordova CLI,创建一个项目,然后我正在运行。我得到准确的数据没有任何问题。但是当我使用 Visual Studio 执行相同的过程时,包含两行或多行文本不会读取。返回荒谬的值(例如:mmm->uuu mmjmmm) 我只能读取一行数据。
如何解决这个问题。这是我的代码
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeFile(image, options);
try {
ExifInterface exif = new ExifInterface(imagePath);
int exifOrientation = exif.getAttributeInt(
ExifInterface.TAG_ORIENTATION,
ExifInterface.ORIENTATION_NORMAL);
int rotate = 0;
switch (exifOrientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
rotate = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
rotate = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
rotate = 270;
break;
}
if (rotate != 0) {
// Getting width & height of the given image.
int w = bitmap.getWidth();
int h = bitmap.getHeight();
// Setting pre rotate
Matrix mtx = new Matrix();
mtx.preRotate(rotate);
// Rotating Bitmap
bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
}
// Convert to ARGB_8888, required by tess
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
} catch (IOException e) {
}
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.setDebug(true);
baseApi.setPageSegMode(1);
baseApi.init(DATA_PATH, lang);
baseApi.setImage(bitmap);
String recognizedText = "";
recognizedText = baseApi.getUTF8Text();
int duration = Toast.LENGTH_SHORT;
Toast.makeText(this.cordova.getActivity().getApplicationContext(),recognizedText, duration).show();
baseApi.end();
recognizedText = recognizedText.trim();
return recognizedText;
我用过这张照片(带相机)
【问题讨论】:
-
是的,我在两个平台都使用相同的图像。例如这个。 codeproject.com/KB/recipes/OCR-Chain-Code/image012.jpg
-
我可以从图片中挑选到手机,也可以用相机来做。情况是,单行文本正确显示,但当两行或多行时,Visual Studio 中的项目显示无意义的值。我把代码加起来。
-
如果您希望人们能够复制您的结果,您应该发布 一个 代表该问题的图像、该图像在两个平台上的结果以及您的预期结果.
-
你有没有尝试过其他的分页方式?
-
是的,我试过了。继续同样的问题。我添加了上面使用的图片。但是我不能添加其他人(我的声誉还不够)。结果如下; i.stack.imgur.com/VrgeG.png 和 i.stack.imgur.com/iHO2b.png 。
标签: android cordova ocr tesseract visual-studio-cordova