Android:通过TessBaseAPI实现ocr中的空间
我有一个问题,我不知道如何在ocr中用空格来表示数字。 Ocr通过我们的共享空间获取所有数字 示例:如果我有一张有数字的图片:657122110 我想退657122110 但是ocr返回657122110,没有空格 这是我的代码:(发件人:) 第二个:(来自:) 你能帮我什么忙?Android:通过TessBaseAPI实现ocr中的空间,android,ocr,space,Android,Ocr,Space,我有一个问题,我不知道如何在ocr中用空格来表示数字。 Ocr通过我们的共享空间获取所有数字 示例:如果我有一张有数字的图片:657122110 我想退657122110 但是ocr返回657122110,没有空格 这是我的代码:(发件人:) 第二个:(来自:) 你能帮我什么忙? 谢谢。为String whiteList=“0123456789”添加空格怎么样?在字符串白名单=“0123456789”中添加空格怎么样? _path = Environment.getExterna
谢谢。为
String whiteList=“0123456789”添加空格怎么样代码>?在字符串白名单=“0123456789”中添加空格怎么样代码>?
_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();
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());