1

我正在研究需要执行 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

请建议我:(

4

2 回答 2

2

如果我对您的理解正确,您想为 BlackBerry 设备实现自己的 OCR 应用程序,并且您想将图像发送到服务器,识别它并将文本文件发送回设备。

有一个开源 OCR 实现,请查看此链接:http ://en.openocr.org/

使用此信息来实现 OCR 服务器功能。黑莓客户端功能将是微不足道的。只需使用HTTPConnection类和流类向服务器上传/下载文件即可。

编辑

注意到 openocr.org 没有直接的源代码下载。他们需要向 cuneiform@cognitive.ru 发送电子邮件请求,他们会考虑。我认为这不是一种方便的方式。

让我们检查另一个来源,例如Tesseract OCR。通过该链接,您可以下载源代码并构建 OCR 应用程序。然后为这个通过 HTTP 工作的应用程序实现 server-wrapper,并编写通过 HTTP 将图像文件上传到该服务器的黑莓客户端,并获取结果文本文件。

于 2012-08-15T08:35:22.187 回答
0

我完成了 OCR 任务。

我从 GitHub 获得的 Java 代码不完整,或者在我这边可能无法正常工作。我已经在我的 PHP 服务器上执行了 OCR 功能。并且它的工作成功。

于 2012-08-20T07:06:50.187 回答