[英]tess-two OCR not decoding correctly
我已經按照教程安裝了Tesseract,特別是安裝了tess-two和eyes-two和我的Android應用程序的一部分。
它運行,但是從baseApi.getUTF8Text();
返回的OCR文本baseApi.getUTF8Text();
是完全亂碼。
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap bmp = BitmapFactory.decodeFile(path , options);
receipt.setImageBitmap(bmp);
try {
ExifInterface exif = new ExifInterface(path);
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) {
int w = bmp.getWidth();
int h = bmp.getHeight();
Matrix matrix = new Matrix();
matrix.preRotate(rotate);
bmp = Bitmap.createBitmap(bmp, 0, 0, w, h, matrix, false);
}
bmp = bmp.copy(Bitmap.Config.ARGB_8888, true);
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(DATA_PATH , "eng");
baseApi.setImage(bmp);
String OCRText = baseApi.getUTF8Text();
baseApi.end();
Log.i("OCR Text", "rotate " + rotate);
Log.i("OCR Text", "OCR ");
Log.i("OCR Text", OCRText);
Log.i("OCR Text", "=======================================================================================");
拍攝具有OCR字符的支票會退貨
05-14 11:01:59.131: I/OCR Text(18199): rotate 90
05-14 11:01:59.131: I/OCR Text(18199): OCR
05-14 11:01:59.131: I/OCR Text(18199): 4— ‘ ‘
05-14 11:01:59.131: I/OCR Text(18199): \Dxfi ‘
05-14 11:01:59.131: I/OCR Text(18199): I W man"! no Accounv
05-14 11:01:59.131: I/OCR Text(18199): 1’
05-14 11:01:59.131: I/OCR Text(18199): my... «unblm m. mm.
05-14 11:01:59.131: I/OCR Text(18199): :~A
05-14 11:01:59.131: I/OCR Text(18199): «Ln.
05-14 11:01:59.131: I/OCR Text(18199): ‘ “w “IN. N I “H‘M‘
05-14 11:01:59.131: I/OCR Text(18199): mmnwnmw- .; k. '
05-14 11:01:59.131: I/OCR Text(18199): Wilt-run”. uni” nl
05-14 11:01:59.131: I/OCR Text(18199): mam. I
05-14 11:01:59.131: I/OCR Text(18199): =======================================================================================
關於如何清理和更正OCR識別的任何建議? 使用的設備是Samsung Galaxy 7”。
您可以使用類似
OCRText = OCRText.replaceAll("[^a-zA-Z0-9]+", " ");
OCRText = OCRText.trim();
它基於我在這里找到的Tesseract實現: SimpleAndroidOCRActivity.java
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.