Android:通过TessBaseAPI在ocr中的空格

时间:2015-09-12 04:08:51

标签: android ocr space

我有一个问题,我不知道如何用ocr中的空格来填充数字。 Ocr用我们的空间获取所有数字..

示例:如果我的图片有数字:65 7 1 22 110 我想要返回65 7 1 22 110 但是ocr返回657122110,没有空格!

这是我的代码:(来自:Simple-Android-OCR

        _path = Environment.getExternalStorageDirectory().toString() + "/DCIM/test.jpg";
    Bitmap bm = BitmapFactory.decodeFile(_path);
    //ByteArrayOutputStream bos = new ByteArrayOutputStream();
    //bm.compress(CompressFormat.JPEG, 75, bos);


    TessBaseAPI baseApi = new TessBaseAPI();
    baseApi.setPageSegMode(TessBaseAPI.OEM_TESSERACT_CUBE_COMBINED);
    baseApi.setPageSegMode(PageSegMode.PSM_AUTO_OSD);
    baseApi.setPageSegMode(PageSegMode.PSM_SINGLE_LINE);
    baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_OSD_ONLY);    

    baseApi.setDebug(true);
    baseApi.init(DATA_PATH, lang);
    baseApi.setImage(ReadFile.readBitmap(bm));

    String whiteList = "0123456789";
    baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, whiteList);

    String recognizedText = baseApi.getUTF8Text();

    baseApi.end();

第二个:(来自:AndroidImageCrop

 String url="http://jimbocho.ocrgrid.org/cgi-bin/weocr/submit_tesseract.cgi";
   response="";
   HttpClient client = new DefaultHttpClient();
   client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
   HttpPost post=new HttpPost(url);
   MultipartEntity entity = new MultipartEntity( HttpMultipartMode.BROWSER_COMPATIBLE );



   //test start
   try {
        Bitmap bm = BitmapFactory.decodeFile("/sdcard/DCIM/test.jpg");
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bm.compress(CompressFormat.JPEG, 75, bos);
        byte[] data = bos.toByteArray();
        ByteArrayBody bab = new ByteArrayBody(data, "testbin.jpg");





   //test end
      entity.addPart("userfile", bab);

    // For usual String parameters
    entity.addPart("outputencoding", new StringBody("utf-8"));
    entity.addPart("outputformat", new StringBody("txt"));

    post.setEntity( entity );
    HttpResponse response = client.execute(post);
    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
    String sResponse;
    StringBuilder s = new StringBuilder();


    while ((sResponse = reader.readLine()) != null) {
        s = s.append(sResponse);
    }


    this.response=new String(s.toString());

怎么能帮到我? 感谢。

0 个答案:

没有答案