0

I develop mobile app that recognize math expressions. I am using opencv and tess-two library. But i take error is that Cannot find local variable 'OpenCVLoader'. Why am I getting this error. How can i fix it.Can you help me please. This is important for graduation project.

static {
    if (!OpenCVLoader.initDebug()) {
        Log.w(TAG, "Unable to load OpenCV");
    } else {
        info("OpenCV loaded");
    }

    // For OCR
    System.loadLibrary("gnustl_shared");
    System.loadLibrary("nonfree");
}

public String getOCRResult(Bitmap bitmap, AssetManager assetMana) {
    mTess = new TessBaseAPI();
    String datapath = Environment.getExternalStorageDirectory() + "/RecognizeTextOCR/";
    File dir = new File(datapath + "tessdata/");
    if (dir.exists()) {
        //dir.mkdirs();
        try {
            InputStream inStream = assetMana.open("CSDL/eng.traineddata");
            FileOutputStream outStream = new FileOutputStream(datapath + "tessdata/eng.traineddata");
            byte[] buffer = new byte[1024];
            int readCount = 0;
            while ((readCount = inStream.read(buffer)) != -1) {
                outStream.write(buffer, 0, readCount);
            }
            outStream.flush();
            outStream.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    mTess.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,"aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ1234567890',.?;/ ");
    mTess.setDebug(true);
    mTess.init(datapath, "eng"); // English
    mTess.setImage(toGrayscale(bitmap));

    String result = mTess.getUTF8Text();

    return result;
}

public Bitmap toGrayscale(Bitmap bmpOriginal)
{
    int width, height;
    height = bmpOriginal.getHeight();
    width = bmpOriginal.getWidth();

    Bitmap bmpGrayscale = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
    Canvas c = new Canvas(bmpGrayscale);
    Paint paint = new Paint();
    ColorMatrix cm = new ColorMatrix();
    cm.setSaturation(0);
    ColorMatrixColorFilter f = new ColorMatrixColorFilter(cm);
    paint.setColorFilter(f);
    c.drawBitmap(bmpOriginal, 0, 0, paint);
    return bmpGrayscale;
}
  • Can you please edit your question and post the code chunk/snippet whatever you tried so far? So that people can help you by suggesting the code changes. – Varun Jain Mar 15 '20 at 17:05
  • I edit my question. I am waiting your help.Thanks – sedaylmz64 Mar 15 '20 at 18:38
  • Please edit your question to include the part of your code that mentions "OpenCVLoader". The code you pasted does not include that text, so cannot be the (sufficient) source of the error – jalanb Mar 16 '20 at 02:00
  • I edit my question that include OpenCvLoader code block.. I am waiting your help.Thanks – sedaylmz64 Mar 16 '20 at 09:20

0 Answers0