mapbox / mapbox-vision-android-teaser

Other
29 stars 13 forks source link

Can I customize the blue area in the image? #229

Open arcpuree opened 3 years ago

arcpuree commented 3 years ago

I want to change the blue area from the image to three colors.

234834234_2048436081972191_4335282346229780161_n

yunikkk commented 2 years ago

@arcpuree is the question still valid?

arcpuree commented 2 years ago

yes, i can not solve the problem. 😂

On Fri, Oct 1, 2021 at 10:41 PM Dmitry Yunitsky @.***> wrote:

@arcpuree https://github.com/arcpuree is the question still valid?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mapbox/mapbox-vision-android-teaser/issues/229#issuecomment-932339623, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEBZ4FMURREUPXWR26MRVE3UEXJCNANCNFSM5DAJ6KOA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- āļ‚āļ­āđāļŠāļ”āļ‡āļ„āļ§āļēāļĄāļ™āļąāļš, Best regards,

āļ āļđāļĢāļĩ āļžāļīāļĄāļžāđŒāļ—āļ­āļ‡āļ‡āļēāļĄ Puree Pimtongngam

089-902-9022 @.***

yunikkk commented 2 years ago

@arcpuree we don't expose API to customize lane render, actually. However, you could draw it yourself using simple Canvas rendering. You'll need to receive RoadDescription object, that contains detected lanes array, for each of them there is two LaneEdges. Each LaneEdge contains Bezier that can be drawn on canvas, e.g.

...
    fun drawLane(lane: Lane?) {
        fillPath.reset()

        lane?.let {
            val leftP1 = VisionManager.worldToPixel(lane.leftEdge.curve.p1)
            val leftP2 = VisionManager.worldToPixel(lane.leftEdge.curve.p2)
            val leftP3 = VisionManager.worldToPixel(lane.leftEdge.curve.p3)
            val leftP4 = VisionManager.worldToPixel(lane.leftEdge.curve.p4)
            val rightP1 = VisionManager.worldToPixel(lane.rightEdge.curve.p1)
            val rightP2 = VisionManager.worldToPixel(lane.rightEdge.curve.p2)
            val rightP3 = VisionManager.worldToPixel(lane.rightEdge.curve.p3)
            val rightP4 = VisionManager.worldToPixel(lane.rightEdge.curve.p4)

            fillPath.apply {
                moveTo(
                    leftP1.x.toFloat(),
                    leftP1.y.toFloat()
                )
                cubicTo(
                    leftP2.x.toFloat(),
                    leftP2.y.toFloat(),
                    leftP3.x.toFloat(),
                    leftP3.y.toFloat(),
                    leftP4.x.toFloat(),
                    leftP4.y.toFloat()
                )

                lineTo(
                    rightP4.x.toFloat(),
                    rightP4.y.toFloat()
                )
                cubicTo(
                    rightP3.x.toFloat(),
                    rightP3.y.toFloat(),
                    rightP2.x.toFloat(),
                    rightP2.y.toFloat(),
                    rightP1.x.toFloat(),
                    rightP1.y.toFloat()
                )
                close()
            }
        }

        invalidate()
    }

    override fun onDraw(canvas: Canvas) {
        canvas.drawPath(fillPath, fillPaint)

        super.onDraw(canvas)
    }
...
arcpuree commented 2 years ago

thank yout, i'll try it. 😄

On Tue, Oct 5, 2021 at 11:29 PM Dmitry Yunitsky @.***> wrote:

@arcpuree https://github.com/arcpuree we don't expose API to customize lane render, actually. However, you could draw it yourself using simple Canvas rendering. You'll need to receive RoadDescription https://docs.mapbox.com/android/vision/api/vision/0.13.0/com/mapbox/vision/mobile/core/models/road/RoadDescription.html object, that contains detected lanes array https://docs.mapbox.com/android/vision/api/vision/0.13.0/com/mapbox/vision/mobile/core/models/road/Lane.html, for each of them there is two LaneEdges https://docs.mapbox.com/android/vision/api/vision/0.13.0/com/mapbox/vision/mobile/core/models/road/LaneEdge.html. Each LaneEdge contains Bezier https://docs.mapbox.com/android/vision/api/vision/0.13.0/com/mapbox/vision/mobile/core/models/BezierCubic3D.html that can be drawn on canvas, e.g.

... fun drawLane(lane: Lane?) { fillPath.reset()

    lane?.let {
        val leftP1 = VisionManager.worldToPixel(lane.leftEdge.curve.p1)
        val leftP2 = VisionManager.worldToPixel(lane.leftEdge.curve.p2)
        val leftP3 = VisionManager.worldToPixel(lane.leftEdge.curve.p3)
        val leftP4 = VisionManager.worldToPixel(lane.leftEdge.curve.p4)
        val rightP1 = VisionManager.worldToPixel(lane.rightEdge.curve.p1)
        val rightP2 = VisionManager.worldToPixel(lane.rightEdge.curve.p2)
        val rightP3 = VisionManager.worldToPixel(lane.rightEdge.curve.p3)
        val rightP4 = VisionManager.worldToPixel(lane.rightEdge.curve.p4)

        fillPath.apply {
            moveTo(
                leftP1.x.toFloat(),
                leftP1.y.toFloat()
            )
            cubicTo(
                leftP2.x.toFloat(),
                leftP2.y.toFloat(),
                leftP3.x.toFloat(),
                leftP3.y.toFloat(),
                leftP4.x.toFloat(),
                leftP4.y.toFloat()
            )

            lineTo(
                rightP4.x.toFloat(),
                rightP4.y.toFloat()
            )
            cubicTo(
                rightP3.x.toFloat(),
                rightP3.y.toFloat(),
                rightP2.x.toFloat(),
                rightP2.y.toFloat(),
                rightP1.x.toFloat(),
                rightP1.y.toFloat()
            )
            close()
        }
    }

    invalidate()
}

override fun onDraw(canvas: Canvas) {
    canvas.drawPath(fillPath, fillPaint)

    super.onDraw(canvas)
}

...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mapbox/mapbox-vision-android-teaser/issues/229#issuecomment-934567935, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEBZ4FMYCZOGK7K56PD4KFLUFMRWLANCNFSM5DAJ6KOA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- āļ‚āļ­āđāļŠāļ”āļ‡āļ„āļ§āļēāļĄāļ™āļąāļš, Best regards,

āļ āļđāļĢāļĩ āļžāļīāļĄāļžāđŒāļ—āļ­āļ‡āļ‡āļēāļĄ Puree Pimtongngam

089-902-9022 @.***