如何使用TextRecognizer显示从图像扫描的文本的框边框

时间:2017-10-09 04:33:38

标签: android ocr

我正在使用tutorial之后的TextRecognizer,我想显示单词框并允许用户选择文字。任何人都可以帮助我如何显示边界的文字?

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() + ", ";
                        }
                    }
                }

            }

0 个答案:

没有答案