我是tess-two图书馆的新手。我可以添加该库并从drawable获取图像,甚至可以转换,但我收到错误的文字如下:
这是我的完整代码:
Bitmap image;
private TessBaseAPI mTess;
String datapath = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//init image
image = BitmapFactory.decodeResource(getResources(), R.drawable.test_image);
//initialize Tesseract API
String language = "eng";
datapath = getFilesDir()+ "/tesseract/";
mTess = new TessBaseAPI();
checkFile(new File(datapath + "tessdata/"));
mTess.init(datapath, language);
}
private void checkFile(File file) {
if (!file.exists()&& file.mkdirs()){
copyFiles();
}
if(file.exists()) {
String datafilepath = datapath+ "/tessdata/eng.traineddata";
File datafile = new File(datafilepath);
if (!datafile.exists()) {
copyFiles();
}
}
}
public void processImage(View view){
String OCRresult = null;
mTess.setImage(image);
OCRresult = mTess.getUTF8Text();
TextView OCRTextView = (TextView) findViewById(R.id.OCRTextView);
OCRTextView.setText(OCRresult);
}
private void copyFiles() {
try {
String filepath = datapath + "/tessdata/eng.traineddata";
AssetManager assetManager = getAssets();
InputStream instream = assetManager.open("tessdata/eng.traineddata");
OutputStream outstream = new FileOutputStream(filepath);
byte[] buffer = new byte[1024];
int read;
while ((read = instream.read(buffer)) != -1) {
outstream.write(buffer, 0, read);
}
outstream.flush();
outstream.close();
instream.close();
File file = new File(filepath);
if (!file.exists()) {
throw new FileNotFoundException();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
我收到的文字如下:
mmmm.and,mmm,1111等
感谢任何帮助。
答案 0 :(得分:1)
我有同样的问题。它已经修复了2分钟前,你必须将图像调整到更大的尺寸。我使用thumbnailator库来完成这项工作:
BufferedImage bigger = Thumbnails.of(oldImage).size(700, 500).asBufferedImage();
我希望这对我可怕的英语有帮助并道歉。
注意:有关调整here
大小的详细信息答案 1 :(得分:0)
可能存在的可能是: