Drawing rectangles on the faces

Now that you have the faces, you will iterate through this array to get the coordinates of the bounding rectangle for the face. Rectangles require x, y of the top left and bottom right corners, but the information available only gives the left and top positions, so you have to calculate the bottom right using the top left, width, and height. Then, you need to release the faceDetector to free up resources. Here's the code:

// Mark out the identified face
for (i in 0 until faces.size()) {
val thisFace = faces.valueAt(i)
val left = thisFace.position.x
val top = thisFace.position.y
val right = left + thisFace.width
val bottom = top + thisFace.height
tempCanvas.drawRoundRect(RectF(left, top, right, bottom), 2F, 2F, myRectPaint)
}

imageView.setImageDrawable(BitmapDrawable(resources, tempBitmap))

// Release the FaceDetector
faceDetector.release()
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset