我正在尝试在Visual Studio(Android版)上使用带有cordova的Tesseract OCR。使用Cordova CLI创建一个项目,然后我就可以运行了。当我在Visual Studio中执行相同的过程时,我可以在没有任何problems.But的情况下获得准确的数据,包含两行或更多行文本不会read.Returns荒诞值(例如:‘m>uuu mmjmmm)我只能读取单行数据。
如何修复这个problem.That是我的代码
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;
我用过这张照片(带相机)
发布于 2015-06-04 17:22:27
如果没有代码示例,我无法确定,但当您通过CLI创建新项目时,您可能正在使用不同的版本号创建项目。
$ cordova create myProject
..。将使用最新版本的Cordova创建一个项目。在撰写本文时,它是5.0版
但是,Visual Studio 2015 RC默认情况下会创建一个Cordova 4.3项目。要更改版本号,请打开config.xml并在"Platforms“选项卡下将Cordova CLI版本号更改为"5.0”。
还可以通过将taco.json添加到项目根目录,在Visual Studio中打开由CLI创建的项目。该文件只需要包含一个json键/值对和您正在使用的CLI的正确版本:
{
"cordova-cli": "5.0.0"
}
您也可以选择在命令行中使用Cordova 4.3.0,方法是使用以下命令安装:
npm install -g cordova@4.3.0
5.0.0是对Cordova的重大修订,因此有许多更改。
https://stackoverflow.com/questions/30621271
复制