我正在研究需要执行 OCR 任务的黑莓核心应用程序。
直到现在我已经搜索并发现很少有像ABBY这样允许读取图像并返回文本文件的在线API,但它们不是免费的,经过几次尝试后它们会收取一定的费用。
我可以通过服务器实现在设备端完全执行光学字符识别吗?请建议我完成这项任务。
编辑:我正在使用以下代码
public String serverUrl = "http://cloud.ocrsdk.com";
static final String BOUNDARY = "----------V2ymHFg03ehbqgZCaKO6jy";
public byte[] send() throws Exception
{
HttpConnection hc = null;
InputStream is = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] res = null;
try
{
hc = (HttpConnection) Connector.open(serverUrl+"/processImage/"+"language=en&exportFormat=txt");
hc.setRequestProperty("Content-Type", "multipart/image-JPG; boundary=" + BOUNDARY);
/*hc = (HttpConnection) Connector.open(SERVICE_URL);
hc.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + BOUNDARY);
hc.setRequestProperty(PARAM_IMAGE, "");
hc.setRequestProperty(PARAM_LANGUAGE, lang);
hc.setRequestProperty(PARAM_APIKEY, key);*/
hc.setRequestMethod(HttpConnection.POST);
OutputStream dout = hc.openOutputStream();
dout.write(raw);
dout.close();
int ch;
StringBuffer sb= new StringBuffer();
is = hc.openInputStream();
while ((ch = is.read()) != -1)
{
bos.write(ch);
sb.append(ch);
}
System.out.println(sb);
res = bos.toByteArray();
}
catch(Exception e){
e.printStackTrace();
}
finally
{
try
{
if(bos != null)
bos.close();
if(is != null)
is.close();
if(hc != null)
hc.close();
}
catch(Exception e2)
{
e2.printStackTrace();
}
}
return res;
}
但即使使用此代码也无法正常工作。发出 HTTP 请求后,我得到 200 作为响应代码。但没有像预期的那样得到完美的回应。作为回应,我收到 ABBYY 的错误页面。 http://cloud.ocrsdk.com/GenericError.htm?aspxerrorpath=/processImage/language=English&exportFormat=txt;connectionhandler=httpc
请建议我:(