【问题标题】:How to draw a rectangle with the real scale of the object?如何用对象的真实比例绘制一个矩形?
【发布时间】:2021-12-18 18:47:33
【问题描述】:

我正在使用 MLKit 库进行条形码扫描,因此我可以获得一个矩形,其中实际上是条形码。但我得到的矩形比条形码小,而且位置不正确。所以,矩形的比例和位置是错误的。

谁能知道如何解决这个问题?有什么方法可以用真实的度量重新缩放和重新定位矩形吗?

谢谢你:)

这是我的代码:

override fun analyze(image: ImageProxy) {
            val img = image.image
            if (img != null) {
                val inputImage = InputImage.fromMediaImage(img, image.imageInfo.rotationDegrees)

                val scanner = BarcodeScanning.getClient()

                scanner.process(inputImage)
                    .addOnSuccessListener { barcodes ->
                        for (barcode in barcodes) {
                            val myRect = barcode.boundingBox
                            // here I draw the rectangle with canvas and paint
                            // ...
                            canvas.drawRect(myRect, mPaint) 
                            // Finish editing pixels in the surface.
                            mHolder.unlockCanvasAndPost(canvas)
                        }
                    }
             }
}

【问题讨论】:

    标签: android drawing rect google-mlkit


    【解决方案1】:

    您可以查看包含 CameraX 场景的ML Kit sample 或查看here 以了解有关坐标变换的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-31
      • 1970-01-01
      • 1970-01-01
      • 2013-03-21
      • 2022-01-04
      • 2021-01-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多