Skip to content

Instantly share code, notes, and snippets.

@Sren-Hmkn
Created August 6, 2018 16:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sren-Hmkn/bdc0e84b829c07dc0cc4de74c6081a45 to your computer and use it in GitHub Desktop.
Save Sren-Hmkn/bdc0e84b829c07dc0cc4de74c6081a45 to your computer and use it in GitHub Desktop.
Add preprateTessData-method to CameraActivity
// public class CameraActivity extends AppCompatActivity implements CameraBridgeViewBase.CvCameraViewListener {...
//
// define a constant of the needed subfolder
public static final String TESS_DATA = "/tessdata";
//
// private static final String TAG = "CameraActivity";
//...
// protected void onCreate(Bundle savedInstanceState) {...
//...
// Call method in onCreate before you create a MyTessOCR instance
prepareTessData();
//
// mTessOCR = new MyTessOCR(this);
//...
// }
//...
//...
// prepare the traineddata on the device (this is not inside of the onCreate method)
private void prepareTessData() {
try {
File dir = getExternalFilesDir(TESS_DATA);
if (!dir.exists()) {
if (!dir.mkdir()) {
Toast.makeText(getApplicationContext(), "The folder " + dir.getPath() + "was not created", Toast.LENGTH_SHORT).show();
}
}
String fileList[] = getAssets().list("tessdata");
for (String fileName : fileList) {
String pathToDataFile = dir + "/" + fileName;
if (!(new File(pathToDataFile)).exists()) {
InputStream in = getAssets().open("tessdata/" + fileName);
OutputStream out = new FileOutputStream(pathToDataFile);
byte[] buff = new byte[1024];
int len;
while ((len = in.read(buff)) > 0) {
out.write(buff, 0, len);
}
in.close();
out.close();
}
}
} catch (Exception e) {
Log.e(TAG, e.getMessage());
}
}
//...
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment