1
有人可以解釋究竟發生了什麼以及如何糾正它。所以我知道tesseract必須有一個圖像的目標,可能這將是我已經捕獲並試圖保存的位圖。該保存的位置將是我的_path變量。現在什麼是用於tesseract的DATA_PATH?圖像是否需要存儲在名爲'tesseract'的文件夾中?我是否創建該文件夾並在其中存儲某種培訓?我正在尋找一個解釋而不是代碼示例。Tesseract - 幫我理解數據路徑
http://gaut.am/making-an-ocr-android-app-using-tesseract/ - 我試圖按照本教程,並檢查其他人試圖瞭解所有人使用的路徑。
public class MainActivity extends Activity {
private static ImageView imageView;
protected String _path;
// protected static Bitmap bit;
static File myDir;
protected static Bitmap mImageBitmap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.imageView = (ImageView) this.findViewById(R.id.imageView1);
Button photoButton = (Button) this.findViewById(R.id.button1);
_path = Environment.getExternalStorageDirectory() + "/images/test.bmp";
Toast t = Toast.makeText(getApplicationContext(), "HEELLLLLLOO", 100000);
t.show();
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// CALL THE PICTURE
dispatchTakePictureIntent(0);
}
});
}
private void handleSmallCameraPhoto(Intent intent) {
Bundle extras = intent.getExtras();
mImageBitmap = (Bitmap) extras.get("data");
imageView.setImageBitmap(mImageBitmap);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 4;
Bitmap bitmap = BitmapFactory.decodeFile(_path, options);
imageView.setImageBitmap(bitmap);
//_path = path to the image to be OCRed
ExifInterface exif;
try {
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 = bitmap.getWidth();
int h = bitmap.getHeight();
// Setting pre rotate
Matrix mtx = new Matrix();
mtx.preRotate(rotate);
// Rotating Bitmap & convert to ARGB_8888, required by tess
bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
bitmap = bitmap.copy(Bitmap.Config.ARGB_8888, true);
}
TessBaseAPI baseApi = new TessBaseAPI();
// DATA_PATH = Path to the storage
// lang for which the language data exists, usually "eng"
baseApi.init(_path, "eng"); //THIS SHOULD BE DATA_PATH ?
baseApi.setImage(bitmap);
String recognizedText = baseApi.getUTF8Text();
System.out.println(recognizedText);
baseApi.end();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
handleSmallCameraPhoto(data);
}
private void dispatchTakePictureIntent(int actionCode) {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(takePictureIntent, actionCode);
}
protected static void identifyunicode() {
// DATA_PATH = Path to the storage
// lang for which the language data exists, usually "eng"
/*
* TessBaseAPI baseApi = new TessBaseAPI();
* baseApi.init(myDir.toString(), "eng"); // myDir + //
* "/tessdata/eng.traineddata" // must be present baseApi.setImage(bit);
* String recognizedText = baseApi.getUTF8Text(); // Log or otherwise //
* display this // string... baseApi.end();
*/
}
}
好的,你說把tessdata文件夾放在Assets中,tessdata文件夾在哪裏?我正在查看tesstwo目錄,但我沒有看到它。 – user1088595 2013-04-26 10:32:52
啊我下載了一個包含tessdata文件夾的Tesseract訓練集,但現在我的應用程序在運行時崩潰了。 「Asset path /data/app/com.example.cameraocr-2.apk既不是目錄也不是文件(type = 1) – user1088595 2013-04-26 10:55:51
@ user1088595您是否看到我的代碼?我正在從'eng.traineddata'文件中複製該文件資產給我創建的Dir。 – 2013-04-29 03:30:14