【问题标题】:How to draw a rectangle on the screen using coordinates with texture view?如何使用带有纹理视图的坐标在屏幕上绘制矩形?
【发布时间】:2020-06-14 13:40:17
【问题描述】:

我正在使用 cameraX 预览到纹理视图的相机馈送。如何使用我拥有的坐标在屏幕上绘制一个矩形?我不想要一个复杂的功能。我只是想画一个矩形。 我正在使用 kotlin 和 android studio 4.0。

【问题讨论】:

    标签: android kotlin textureview


    【解决方案1】:

    我会在同一个 xml 的 Textureview 顶部使用 ImageView 重叠。此图像视图将加载一个仅绘制矩形的透明位图。如果你有你必须做的坐标:

    val myRectPaint = Paint()
    myRectPaint.strokeWidth = 5F
    myRectPaint.color = Color.RED
    myRectPaint.style = Paint.Style.STROKE
    
    // Create a Canvas object for drawing on the original bitmap provided
    val tempBitmap =
        Bitmap.createBitmap(bitmap!!.width, bitmap.height, Bitmap.Config.ARGB_8888)
    val tempCanvas = Canvas(tempBitmap)
    tempCanvas.drawBitmap(bitmap, 0F, 0F, null)
    
    tempCanvas.drawRoundRect(
                RectF(x1.toFloat(), y1.toFloat(), x2.toFloat(), y2.toFloat()),
                2f,
                2f,
                myRectPaint
            )
    
    // Use this to widen picture on top or bottom
        val croppedFaceBitmap =
            Bitmap.createBitmap(tempBitmap, x1, y1, x2, y2)
    

    无论如何,您也可以从 tensorflow github 关注this example,在检测到对象时绘制圆框。

    希望我能帮上忙

    【讨论】:

    • Sundar,在这种情况下,请遵循对象检测的官方 tensorflow 项目的示例...构建它以查看矩形是如何绘制的...如果适合您的情况,请遵循它。跨度>
    • 我已经尝试解决这个问题了 6 个小时,但似乎没有任何效果。如果我与你分享链接,你能看看我的项目吗?
    • 是的,一定要分享!
    • 我正在努力。我无法构建项目。但是我在第 186-200 行的分类器文件中看到,您没有使用任何地方的解释器推断产生的 outputMap。为什么??
    • 其实我不需要那个输出映射,我直接在解释器推理线下面的for循环中使用它的内部数据变量。但我能够构建项目,我这边没有错误
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-25
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多