Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to align rectangles in draw with roboflow and jetpack compose?

I’m trying to implement a feature to detect manga bubble speech.

I’m taking a screenshot of my device and receiving the response from the API, and as soon as it returns, I draw some rectangles with canvas. But I can’t seem to align these rectangles in any way.

My Code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

@Composable
internal fun ScreenShotDrawSpeech(
    bubbleDomain: BubbleDomain,
    modifier: Modifier = Modifier,
) {
    Canvas(
        modifier = modifier
            .fillMaxSize()
            .background(background_overlay),
        onDraw = {
            bubbleDomain.predictions.forEach { prediction ->
                val left = prediction.x
                val top = prediction.y

                drawRect(
                    color = Color.Red,
                    topLeft = Offset(left.toFloat(), top.toFloat()),
                    size = Size(prediction.width.toFloat(), prediction.height.toFloat()),
                    style = Stroke(width = 2f),
                )
            }
        },
    )
}

Result:

Screenshot_20240506_091529

>Solution :

The coordinates of your predictions seem to specify the center of the bubble.

Ue this to determine the left and top of the rectangle instead:

val left = prediction.x - prediction.width / 2
val top = prediction.y - prediction.height / 2
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading