Я изучаю Android, используя NDK с opencv.
Я успешно использую ndk. Поэтому я получаю полезные данные (я имею в виду, что данные были сделаны canny.)
Когда я использую Tesseract,
Файл данных не найден в /storage/emulated/0/tesseract/tessdata/eng.traineddata
Произошла эта ошибка.
Я уже проверил adroid / app / src / main / assets / tessdata / eng.traineddata
есть обученные данные ....
Я не знаю, почему я получаю ошибку там.
плз ... помогите пожалуйста ...
public class ocrActivity extends AppCompatActivity {
private static final String TAG = "opencv";
private Mat matInput=new Mat();
private Mat matResult=new Mat();
private Mat matFinal=new Mat();
public Uri luck;
public Bitmap testbm;
public Bitmap resultbm;
public native void ConvertRGBtoGray(long matAddrInput, long matAddrResult);
static {
System.loadLibrary("opencv_java3");
System.loadLibrary("native-lib");
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
setContentView(R.layout.activity_ocr);
ImageView iv1 = findViewById(R.id.imageview01);
Uri data = null;
Intent takePhoto = getIntent();
String flag = takePhoto.getStringExtra("flag");
if (flag.equals("imageUri")) {
data = takePhoto.getParcelableExtra("imageUri");
} else if (flag.equals("albumURI")) {
data = takePhoto.getParcelableExtra("albumURI");
}
luck = data;
testbm=test123();
//
Utils.bitmapToMat(testbm,matInput);
if ( matResult == null )
matResult = new Mat(matInput.rows(), matInput.cols(), matInput.type());
ConvertRGBtoGray(matInput.getNativeObjAddr(), matResult.getNativeObjAddr());
Utils.matToBitmap(matResult,testbm);
iv1.setImageBitmap(testbm);
----------------Doing very Well--------------------------
TessOCR mTessOCR = new TessOCR();
String result = mTessOCR.getOCRResult(testbm);
System.out.println(result);
}
public class TessOCR {
private TessBaseAPI mTess;
public TessOCR() {
// TODO Auto-generated constructor stub
mTess = new TessBaseAPI();
String datapath = Environment.getExternalStorageDirectory() + "/tesseract/";
String language = "eng";
File dir = new File(datapath + "tessdata/");
if (!dir.exists())
dir.mkdirs();
mTess.init(datapath, language);
}
public String getOCRResult(Bitmap bitmap) {
mTess.setImage(bitmap);
String result = mTess.getUTF8Text();
return result;
}
public void onDestroy() {
if (mTess != null)
mTess.end();
}
}
/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
public native String stringFromJNI();
public Bitmap test123() {
Uri photo = fuck;
Bitmap bm=null;
try {
bm = MediaStore.Images.Media.getBitmap(getContentResolver(), photo);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return bm;
}
}
Код ошибки!
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.z2_sooodt.ocr/com.example.z2_sooodt.ocr.ocrActivity}: java.lang.IllegalArgumentException: Data file not found at /storage/emulated/0/tesseract/tessdata/eng.traineddata
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
Caused by: java.lang.IllegalArgumentException: Data file not found at /storage/emulated/0/tesseract/tessdata/eng.traineddata
at com.googlecode.tesseract.android.TessBaseAPI.init(TessBaseAPI.java:339)
at com.googlecode.tesseract.android.TessBaseAPI.init(TessBaseAPI.java:303)
at com.example.z2_sooodt.ocr.ocrActivity$TessOCR.<init>(ocrActivity.java:110)
at com.example.z2_sooodt.ocr.ocrActivity.onCreate(ocrActivity.java:88)
at android.app.Activity.performCreate(Activity.java:6679)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)