【问题标题】:What does the elements.getBoundingBox output mean? (FirebaseVision, android)elements.getBoundingBox 输出是什么意思? (FirebaseVision,安卓)
【发布时间】:2020-01-30 22:31:20
【问题描述】:

在使用 Firebase-MLKit 库提取的元素上使用 getBoundingBox 方法时,它会为您提供如下所示的输出

Rect(0, 0 - 13, 33)

每个数字代表什么?

相关代码

private void processTextRecognitionResults(FirebaseVisionText receipt) {

        List<FirebaseVisionText.TextBlock> blocks = receipt.getTextBlocks();
        List<FirebaseVisionText.Element> elements;
        if (blocks.size() == 0) {
            Toast.makeText(this, "No text found", Toast.LENGTH_SHORT).show();
            return;
        }

        for (int runThroBlocks = 0; runThroBlocks < blocks.size(); runThroBlocks++) {
            List<FirebaseVisionText.Line> lines = blocks.get(runThroBlocks).getLines();
            for (int runThroLines = 0; runThroLines < lines.size(); runThroLines++) {
                elements = lines.get(runThroLines).getElements();
                for (int runThroElemnts = 0; runThroElemnts < elements.size(); runThroElemnts++) {
                    System.out.println("-----BOX-----");
                    System.out.println(elements.get(runThroElemnts).getText());
                    //This line prints the output given above
                    System.out.println(elements.get(runThroElemnts).getBoundingBox());
                    System.out.println("-----BOX-----");

                }
            }
        }

如果问题写得不好,请见谅。这是我第一次写 感谢您的帮助

【问题讨论】:

    标签: android firebase-mlkit


    【解决方案1】:

    getBoundingBox() 函数返回一个android.graphics.Rect object

    打印elements.get(runThroElemnts).getText() 时调用的toString implementation 将它们打印为lefttoprightbottom

        public String toString() {
            StringBuilder sb = new StringBuilder(32);
            sb.append("Rect("); sb.append(left); sb.append(", ");
            sb.append(top); sb.append(" - "); sb.append(right);
            sb.append(", "); sb.append(bottom); sb.append(")");
            return sb.toString();
        }
    

    【讨论】:

    • 首先感谢您的帮助。 “左、上、右、下”是否从中间以像素表示?还是作为来自边界的 dp?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-29
    • 1970-01-01
    • 2018-07-17
    • 2020-11-09
    • 2011-12-19
    相关资源
    最近更新 更多