extracting numbers from Bitmap in android using tess-two library
<p>I want to extract a number from a Bitmap. I'm using the <code>tess-two</code> library, but it does not recognize correctly. </p>

<p><strong>Example Code:</strong></p>

<pre><code>    @Override
        public void onClick(View v) {
        switch (v.getId()){
        case R.id.b2:
        InputStream is = null;
        try {
        is = getApplicationContext().getAssets().open("zak.jpeg");
        } catch (IOException e1) {
        e1.printStackTrace();
        }
         final Drawable drw = Drawable.createFromStream(is, null);
         bmp = ((BitmapDrawable) drw).getBitmap();

        TessBaseAPI baseApi = new TessBaseAPI();
           bmp =BITMAP_RESIZER(bmp,bmp.getWidth(),bmp.getHeight());
            bmp =convertToGrayscale(bmp);
             bmp =RemoveNoise(bmp);
             iv.setImageBitmap(bmp);

          baseApi.init("/mnt/sdcard/Download/", "eng");
          baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,"1234567890");
          baseApi.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST,"!@#$%^&amp;*   ()_+=-[]}{" +";:'\"\\|~`,./&lt;&gt;?");
          baseApi.setDebug(true);
         baseApi.setImage(bmp);

        String recognizedText = baseApi.getUTF8Text();
        tv.setText(" numbers : "+recognizedText.trim());
        Log.d("karim", recognizedText);
        baseApi.end();
             break;
</code></pre>

<p>Method to convert the Bitmap to grayscale: </p>

<pre><code> public static Bitmap convertToGrayscale(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;
     }
</code></pre>

<p>Method to remove the noise from the Bitmap: </p>

<pre><code>  public Bitmap RemoveNoise(Bitmap bmap) {
        for (int x = 0; x &lt; bmap.getWidth(); x++) {
        for (int y = 0; y &lt; bmap.getHeight(); y++) {
        int pixel = bmap.getPixel(x, y);
        int R = Color.red(pixel);
        int G = Color.green(pixel);
        int B = Color.blue(pixel);
        if (R &lt; 162 &amp;&amp; G &lt; 162 &amp;&amp; B &lt; 162)
        bmap.setPixel(x, y, Color.BLACK);
        }
    }
        for (int  x = 0; x &lt; bmap.getWidth(); x++) {
        for (int y = 0; y &lt; bmap.getHeight(); y++) {
        int pixel = bmap.getPixel(x, y);
        int R = Color.red(pixel);
        int G = Color.green(pixel);
        int B = Color.blue(pixel);
        if (R &gt; 162 &amp;&amp; G &gt; 162 &amp;&amp; B &gt; 162)
              bmap.setPixel(x, y, Color.WHITE);
        }
    }
       return bmap;
    }
</code></pre>

<p>Method to resize the bitmap:</p>

<pre><code>   public Bitmap BITMAP_RESIZER(Bitmap bitmap,int newWidth,int newHeight) 
      {    
    Bitmap scaledBitmap = Bitmap.createBitmap(newWidth, newHeight, Config.ARGB_8888);

    float ratioX = newWidth / (float) bitmap.getWidth();
    float ratioY = newHeight / (float) bitmap.getHeight();
    float middleX = newWidth / 2.0f;
    float middleY = newHeight / 2.0f;

    Matrix scaleMatrix = new Matrix();
    scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);

    Canvas canvas = new Canvas(scaledBitmap);
    canvas.setMatrix(scaleMatrix);
    canvas.drawBitmap(bitmap, middleX - bitmap.getWidth() / 2, middleY - bitmap.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG));

    return scaledBitmap;

    }
</code></pre>

<p><img src="https://i.stack.imgur.com/KSxg6.png" alt="The incorrect result."></p>

<p>How do I fix this problem?</p>