Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@ import com.google.firebase.samples.apps.mlkit.common.GraphicOverlay
/** Graphic instance for rendering detected landmark. */
class CloudLandmarkGraphic(overlay: GraphicOverlay) : GraphicOverlay.Graphic(overlay) {

private val rectPaint: Paint = Paint()
private val landmarkPaint: Paint
private lateinit var landmark: FirebaseVisionCloudLandmark

init {

rectPaint.color = TEXT_COLOR
rectPaint.style = Paint.Style.STROKE
rectPaint.strokeWidth = STROKE_WIDTH

landmarkPaint = Paint()
landmarkPaint.color = TEXT_COLOR
landmarkPaint.textSize = TEXT_SIZE
private val rectPaint = Paint().apply {
color = TEXT_COLOR
style = Paint.Style.STROKE
strokeWidth = STROKE_WIDTH
}
private val landmarkPaint = Paint().apply {
color = TEXT_COLOR
textSize = TEXT_SIZE
}
private var landmark: FirebaseVisionCloudLandmark? = null

/**
* Updates the landmark instance from the detection of the most recent frame. Invalidates the
Expand All @@ -38,30 +34,29 @@ class CloudLandmarkGraphic(overlay: GraphicOverlay) : GraphicOverlay.Graphic(ove
* Draws the landmark block annotations for position, size, and raw value on the supplied canvas.
*/
override fun draw(canvas: Canvas) {
if (landmark == null) {
throw IllegalStateException("Attempting to draw a null landmark.")
}
if (landmark.landmark == null || landmark.boundingBox == null) {
return
}

// Draws the bounding box around the LandmarkBlock.
val rect = RectF(landmark.boundingBox)
with(rect) {
left = translateX(left)
top = translateY(top)
right = translateX(right)
bottom = translateY(bottom)
canvas.drawRect(this, rectPaint)

// Renders the landmark at the bottom of the box.
canvas.drawText(landmark.landmark, left, bottom, landmarkPaint)
}
landmark?.let { lm ->
if (lm.landmark == null || lm.boundingBox == null) {
return
}

// Draws the bounding box around the LandmarkBlock.
val rect = RectF(lm.boundingBox)
with(rect) {
left = translateX(left)
top = translateY(top)
right = translateX(right)
bottom = translateY(bottom)
canvas.drawRect(this, rectPaint)

// Renders the landmark at the bottom of the box.
canvas.drawText(lm.landmark, left, bottom, landmarkPaint)
}
} ?: kotlin.run { throw IllegalStateException("Attempting to draw a null landmark.") }
}

companion object {
private const val TEXT_COLOR = Color.WHITE
private const val TEXT_SIZE = 54.0f
private const val STROKE_WIDTH = 4.0f
}
}
}