Android tesseract数据路径
问题描述:
所以我正在学习下面的教程,下面是我的代码。我一直在试图弄清楚我需要的数据路径。有没有人有关于如何拍摄我拍摄的位图照片并将其加载到tesseract中进行分析的示例或建议?所有帮助赞赏。Android tesseract数据路径
package com.example.cameraocr;
import java.io.File;
import com.googlecode.tesseract.android.TessBaseAPI;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
import android.view.Menu;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
private static final int CAMERA_REQUEST = 1888;
private static ImageView imageView;
@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);
photoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == CAMERA_REQUEST && resultCode == RESULT_OK) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
}
}
protected static void identifyunicode() {
// DATA_PATH = Path to the storage
// lang for which the language data exists, usually "eng"
File myDir = getExternalFilesDir(Environment.MEDIA_MOUNTED);
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(myDir, "eng");
}
}
答
在我的例子看看:
我所做的就是调用摄像头,拍摄照片,让照片并把它传递给我的OCRTask
类(一个的AsyncTask)的调用TessBaseAPI
public void callCamera() {
Log.d(TAG, "Starting camera...");
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, REQUEST_OCR);
}
https://github.com/akiwarheit/plug-notes-android/blob/master/src/com/plug/note/OCRTask.java
(有点长,如果我张贴在这里的整个OCRTask
类代码,所以刚读它在Github上,也许?)
而且事后
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
/* bunch of other codes */
if (requestCode == REQUEST_OCR) {
if (resultCode == RESULT_OK) {
Bitmap x = (Bitmap) data.getExtras().get("data");
new OCRTask(this, x, this).execute();
}
}
}
我只是增加了它认识到文字处理结果我EditText
@Override
public void onFinishRecognition(String recognizedText) {
noteView.setText(noteView.getText() + " " + recognizedText);
}
这里是类
NoteEditor (calls the Camera intent)
OCRTask (calls the TessBaseApi
, this is your main concern)
OCRCallback (Adds the text to my EditText
after OCRTask
finishes)
希望它能帮助。