[英]Android tesseract data path
So I'm following tutorials and below is my code. 所以我正在学习教程,下面是我的代码。 I'm stuck trying to figure out what I need to with the data path. 我一直在努力弄清楚数据路径需要做什么。 Does anyone have an example or suggestion on how to take the bitmap photo I took and get it loaded into tesseract to analyze? 有没有人对如何拍摄我拍摄的位图照片并将其加载到tesseract中进行分析的示例或建议? All help appreciated. 所有帮助表示赞赏。
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");
}
}
take a look at my example: 看一下我的例子:
https://github.com/akiwarheit/plug-notes-android/blob/master/src/com/plug/note/NoteEditorActivity.java https://github.com/akiwarheit/plug-notes-android/blob/master/src/com/plug/note/NoteEditorActivity.java
What I did was call the camera, take a photo, get the photo and pass it to my OCRTask
class (an AsyncTask) which calls the TessBaseAPI
我所做的就是调用相机,拍照,获取照片并将其传递给我的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 https://github.com/akiwarheit/plug-notes-android/blob/master/src/com/plug/note/OCRTask.java
(A bit long if I post the entire OCRTask
class code here, so just read it in Github, maybe?) (如果我在此处发布整个OCRTask
类代码有点长,那么也许可以在Github中阅读它)?
And handled the result afterwards 然后处理结果
@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();
}
}
}
I just added the text it recognized to my EditText
我刚刚将它识别的文本添加到了我的EditText
@Override
public void onFinishRecognition(String recognizedText) {
noteView.setText(noteView.getText() + " " + recognizedText);
}
Here are the classes 这是课程
NoteEditor (calls the Camera intent) NoteEditor(调用Camera Intent)
OCRTask (calls the TessBaseApi
, this is your main concern) OCRTask(称为TessBaseApi
,这是您主要关心的问题)
OCRCallback (Adds the text to my EditText
after OCRTask
finishes) OCRCallback(在OCRTask
完成后将文本添加到我的EditText
)
FileManager (util method) FileManager(util方法)
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.