【问题标题】:How to Extract Name,Phone Number and Email Address From Vision OCR result text in Android?如何从 Android 中的 Vision OCR 结果文本中提取姓名、电话号码和电子邮件地址?
【发布时间】:2017-05-05 13:36:47
【问题描述】:

这是我想要获取详细信息的示例代码...

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PHOTO_REQUEST && resultCode == RESULT_OK) {
        launchMediaScanIntent();
        try {
            Bitmap bitmap = decodeBitmapUri(this, imageUri);
            if (detector.isOperational() && bitmap != null) {
                Frame frame = new Frame.Builder().setBitmap(bitmap).build();
                SparseArray<TextBlock> textBlocks = detector.detect(frame);
                String blocks = "";
                String lines = "";
                String words = "";
                for (int index = 0; index < textBlocks.size(); index++) {
                    //extract scanned text blocks here
                    TextBlock tBlock = textBlocks.valueAt(index);
                    blocks = blocks + tBlock.getValue() + "\n" + "\n";
                    for (Text line : tBlock.getComponents()) {
                        //extract scanned text lines here
                        lines = lines + line.getValue() + "\n";

                        for (Text element : line.getComponents()) {
                            //extract scanned text words here
                            words = words + element.getValue() + ", ";
                        }
                    }
                }


                if (textBlocks.size() == 0) {
                    scanResults.setText("Scan Failed: Found nothing to scan");
                } else {
                    scanResults.setText(scanResults.getText() + "Blocks: " + "\n");
                    scanResults.setText(scanResults.getText() + blocks + "\n");
                    scanResults.setText(scanResults.getText() + "---------" + "\n");
                    scanResults.setText(scanResults.getText() + "Lines: " + "\n");
                    scanResults.setText(scanResults.getText() + lines + "\n");
                    scanResults.setText(scanResults.getText() + "---------" + "\n");
                    scanResults.setText(scanResults.getText() + "Words: " + "\n");
                    scanResults.setText(scanResults.getText() + words + "\n");
                    scanResults.setText(scanResults.getText() + "---------" + "\n");
                }
            } else {
                scanResults.setText("Could not set up the detector!");
            }
        } catch (Exception e) {
            Toast.makeText(this, "Failed to load Image", Toast.LENGTH_SHORT).show();
            Log.e(LOG_TAG, e.toString());
        }
    }
}

【问题讨论】:

  • 你找到解决办法了吗?
  • 你有解决方案吗?也请帮我解决。

标签: android google-api ocr vision image-scanner


【解决方案1】:

你有很好的库来解析链接(电子邮件、网站等),比如 org.nibor.autolink 关于数字,您可以查看 libphonenumber。它由google提出并被android使用。如果您提供国家/地区,它可以为您解析任何格式的数字。

关于名字很难。如果您仅在一个国家/地区使用您的应用程序,您可以使用名称创建一个数据库(在法国,我们在 opendata 中有一个由公共服务提出的文件),但它不会是完整的......

【讨论】:

猜你喜欢
  • 2013-06-30
  • 1970-01-01
  • 2014-02-12
  • 2021-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-07
相关资源
最近更新 更多