First understand that, view coordinate system has different dimensions than captured image given same distance is covered.
And face bounding box coordinates is in image coordinate system.
So you need transform 1 coordinate system to otherby scaling up or down.
Find Display coordinates
val displayMetrics = context.resources.displayMetrics
val screenWidth = displayMetrics.widthPixels
val screenHeight = displayMetrics.heightPixels
val density = displayMetrics.density
From image size from imageproxy from camera api
val imageWidth = imageProxy.width
val imageHeight = imageProxy.height
Find scale by comparing both
val scaleX = screenWidth.toFloat() / imageWidth.toFloat()
val scaleY = screenHeight.toFloat() / imageHeight.toFloat()
get scaled width to be used to get face bounding box actual left right positions in next steps
scaledScreenWidth = screenWidth / scaleX
Get your view positions
val radius: Float = getCircleDiameter() / 2.toFloat() * density
val centerX = screenWidth / 2
val centerY = screenHeight/ 2
find frame coordinates
val frameLeft = (centerX - radius) / scaleX
val frameRight = (centerX + radius) / scaleX
val frameTop = (centerY - radius) / scaleY
val frameBottom = (centerY + radius) / scaleY
frameRect = Rect(frameLeft, frameTop, frameRight, frameBottom)
find face coordinates
NOte -> for front camera since its mirror image, to get actual left, right you need to get it reversed from current left right
val faceLeft = scaledScreenWidth - face.boundingBox.right
val faceRight = scaledScreenWidth - face.boundingBox.left
val faceTop = face.boundingBox.top.toFloat()
val faceBottom = face.boundingBox.bottom.toFloat()
Now you have face and frame coordinates in same coordinate system.
You can compare easily.
NOte -> we have converted view coordinates to image, so that its a one time step, since view coordinates dont change, and not bringing it to image coordinates, you can always compare by every new face detected without recalculating frame coordinates.