Created
August 6, 2018 16:55
-
-
Save Sren-Hmkn/bdc0e84b829c07dc0cc4de74c6081a45 to your computer and use it in GitHub Desktop.
Add preprateTessData-method to CameraActivity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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