Skip to content

Instantly share code, notes, and snippets.

@Sren-Hmkn
Created August 6, 2018 16:20
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/ee80695947b4744591d19051c106a760 to your computer and use it in GitHub Desktop.
Save Sren-Hmkn/ee80695947b4744591d19051c106a760 to your computer and use it in GitHub Desktop.
Call MyTessOCR class from CameraActivity
//...
//...
//...
// Mat usedMat;
MyTessOCR mTessOCR;
Bitmap bitmap;
//
// BaseLoaderCallback mLoaderCallBack = new BaseLoaderCallback(this){...}
//...
//...
// protected void onCreate(Bundle savedInstanceState) {
//...
// javaCameraView.setCvCameraViewListener(this);
mTessOCR = new MyTessOCR(this);
//...
// makeNormal = (Button) findViewById(R.id.normal_mode);
//...
// makeRead.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// since the computation of the OCR could be process-demanding,
// we will call it in an extra thread.
AsyncOcrTask task = new AsyncOcrTask();
task.execute();
// }
// });
// }
//...
private class AsyncOcrTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... voids){
String temp = "not working";
bitmap = Bitmap.createBitmap(usedMat.cols(),usedMat.rows(), Bitmap.Config.ARGB_4444);
try {
bitmap = Bitmap.createBitmap(usedMat.cols(), usedMat.rows(), Bitmap.Config.ARGB_4444);
Utils.matToBitmap(usedMat, bitmap);
// Getting width & height of the given image.
int w = bitmap.getWidth();
int h = bitmap.getHeight();
// Setting rotation, according to our changes in OpenCV library,
// because we only changed the rotation in the preview, not in the actual inputStream
Matrix mtx = new Matrix();
mtx.postRotate(90);
// Rotating Bitmap
bitmap = Bitmap.createBitmap(bitmap, 0, 0, w, h, mtx, false);
temp = mTessOCR.getOCRResult(bitmap);
}catch(Exception ex){
Log.d("Exception",ex.getMessage());
}
return temp;
}
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment