gpt4 book ai didi

android - tesseract 数据路径不存在

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:42:23 25 4
gpt4 key购买 nike

我正在尝试从 Android 中捕获的任何图像中提取文本。所以我创建了一个 Intent 来访问相机并使用 startActivityForResult 启动它。

这是我的 onActivityResult 代码:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
Bundle extras = data.getExtras();
Bitmap bitmap = (Bitmap) extras.get("data");
TextView res = (TextView) findViewById(R.id.hello);
//imageView.setImageBitmap(imageBitmap);
//Image image = ImageIO.read(imageFile);
//BufferedImage buffimg = (BufferedImage) image;
//BufferedImage img = ImageHelper.convertImageToGrayscale(buffimg);
//ITesseract instance = new Tesseract(); // JNA Interface Mapping
//ITesseract instance = new Tesseract1(); // JNA Direct Mapping

//TessDataManager.initTessTrainedData(context);
if(isStoragePermissionGranted() == true) {
TessBaseAPI tessBaseAPI = new TessBaseAPI();

String path = Environment.getExternalStorageDirectory() + "/";
//String path = "/mnt/sdcard/";

tessBaseAPI.setDebug(true);
tessBaseAPI.init(path, "eng");


tessBaseAPI.setImage(bitmap);

String text = tessBaseAPI.getUTF8Text();
tessBaseAPI.end();
res.setText(text);
}
}
else
{
TextView res = (TextView) findViewById(R.id.hello);
res.setText("Well damn");
}


}


}
public boolean isStoragePermissionGranted() {
if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Log.v(TAG,"Permission is granted");
return true;
} else {

Log.v(TAG,"Permission is revoked");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 1);
return false;
}
}
else { //permission is automatically granted on sdk<23 upon installation
Log.v(TAG, "Permission is granted");
return true;
}


}

我收到的错误是:

java.lang.RuntimeException: Unable to resume activity {com.example.abc.snaptravel/com.example.abc.snaptravel.MainActivity}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { act=inline-data dat=content: (has extras) }} to activity {com.example.abc.snaptravel/com.example.abc.snaptravel.MainActivity}: java.lang.IllegalArgumentException: Data path does not exist!

具体来说:

Data path does not exist

我阅读了很多有关此问题的资料,并尝试了许多不同的解决方案。我也尝试过在路径名中使用和不使用 "/tessdata/"

如果您有任何建议,我将不胜感激。谢谢!

最佳答案

好吧,我以为 Environment.getExternalStorageDirectory() 指向我的 SD 卡,但事实并非如此。它指向我的内部存储。那是我错的地方。我复制了内部存储中的 tessdata 文件夹,现在它可以正常工作了。

关于android - tesseract 数据路径不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38934471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com