Skip to content

Instantly share code, notes, and snippets.

@qichuan
Last active July 10, 2018 13:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qichuan/f907e42db0798bc9a1e6b0b7bf3b4000 to your computer and use it in GitHub Desktop.
Save qichuan/f907e42db0798bc9a1e6b0b7bf3b4000 to your computer and use it in GitHub Desktop.
/**
* Draw cigarette at the left mouth
*/
private fun drawCigarette(canvas: Canvas, face: FirebaseVisionFace) {
val rightMouth = face.getLandmark(FirebaseVisionFaceLandmark.RIGHT_MOUTH)
val leftMouth = face.getLandmark(FirebaseVisionFaceLandmark.LEFT_MOUTH)
if (leftMouth != null && rightMouth != null) {
val mouthLength = ((leftMouth.position.x - rightMouth.position.x) * widthScaleFactor).toInt()
val cigaretteRect = Rect(
translateX(leftMouth.position.x).toInt() - mouthLength,
translateY(leftMouth.position.y).toInt(),
translateX(leftMouth.position.x).toInt(),
translateY(leftMouth.position.y).toInt() + mouthLength
)
canvas.drawBitmap(cigaretteBitmap, null, cigaretteRect, null)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment