WepsTech
The world of development
In this chapter I am going to cover Landmark detection
in image. Before coming to this chapter you have to go through with How to start with ML in android – Part 1. Because in that post I have already covered the basic integration of ML. Now I am going to tell you solution for how to detect the landmark.
Everything will be remain same as we have integrate in the last chapter, You have to integrate some more lines of code in FaceOverlayView
class. So let’s create a new function drawFaceLandmarks()
. Your function will look like the below code.
private fun drawFaceLandmarks(canvas: Canvas, scale: Double) {
val paint = Paint()
paint.color = Color.GREEN
paint.style = Paint.Style.STROKE
paint.strokeWidth = 5.0f
for (i in 0 until mFaces?.size()!!) {
val face = mFaces?.valueAt(i)
if (face != null) {
for (landmark in face.landmarks) {
val cx = (landmark.position.x * scale).toInt()
val cy = (landmark.position.y * scale).toInt()
canvas.drawCircle(cx.toFloat(), cy.toFloat(), 10.0f, paint)
}
}
}
}
This function will draw a circle on your landmark. And you have to call this function from override fun onDraw(canvas: Canvas)
. Officially you can detect 8
landmark on the face. According to these 8
landmark you can create any kind of face shape in your mobile application. And this process comes under the image processing.