Skip to content

Commit

Permalink
fix get frame rotation degrees
Browse files Browse the repository at this point in the history
  • Loading branch information
luicfrr committed Apr 22, 2024
1 parent 75a668c commit ffcd398
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.google.mlkit.vision.face.FaceDetector
import com.google.mlkit.vision.face.FaceDetectorOptions
import com.google.mlkit.vision.face.FaceLandmark
import com.mrousavy.camera.core.FrameInvalidError
import com.mrousavy.camera.core.types.Orientation
import com.mrousavy.camera.frameprocessors.Frame
import com.mrousavy.camera.frameprocessors.FrameProcessorPlugin
import com.mrousavy.camera.frameprocessors.VisionCameraProxy
Expand Down Expand Up @@ -229,16 +230,27 @@ class VisionCameraFaceDetectorPlugin(
return faceContoursTypesMap
}

private fun getFrameRotation(
orientation: Orientation
): Int {
return when (orientation) {
Orientation.PORTRAIT -> 0
Orientation.LANDSCAPE_LEFT -> 90
Orientation.PORTRAIT_UPSIDE_DOWN -> 180
Orientation.LANDSCAPE_RIGHT -> 270
}
}

override fun callback(
frame: Frame,
params: Map<String, Any>?
): Any {
val result = ArrayList<Map<String, Any>>()

try {
val rotation = frame.orientation.toSurfaceRotation()
val rotation = getFrameRotation(frame.orientation)
val image = InputImage.fromMediaImage(frame.image, rotation)

val sourceWidth: Double
val sourceHeight: Double
if (rotation == 270 || rotation == 90) {
Expand Down

0 comments on commit ffcd398

Please sign in to comment.