I am trying to detect faces from a bitmap and my image rotation is set to 90, whenever that happens the detector fails. If i set it to 0 and twist my phone to landscape it will work and detect my face. Any idea what's going on?
Code below (args.bitmapImage coming from a cameraX fragment not shown)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
val binding = DataBindingUtil.inflate<FragmentReviewImageBinding>(
inflater, R.layout.fragment_review_image, container, false)
// Inflate the layout for this fragment
val args = reviewImageFragmentArgs.fromBundle(requireArguments())
binding.imageView.rotation = args.rotation
binding.imageView.setImageBitmap(args.bitmapImage)
val rot = args.rotation.toInt()
Log.d("rot","Rotation is $rot") <--- mine is set to 90
//binding.imageView.scaleType = ImageView.ScaleType.FIT_XY
detectFace(args.bitmapImage,args.rotation)
return binding.root
}
private fun detectFace(bitmap: Bitmap, rotation:Float) {
val highAccuracyOpts = FaceDetectorOptions.Builder()
.setPerformanceMode(FaceDetectorOptions.PERFORMANCE_MODE_ACCURATE)
.setLandmarkMode(FaceDetectorOptions.LANDMARK_MODE_ALL)
.setContourMode(FaceDetectorOptions.CONTOUR_MODE_ALL)
.build()
val image = InputImage.fromBitmap(bitmap,rotation) <---- when i hard code this to 0 it actually works but i have to turn my phone, but if this val is not 0, it fails)
val detector = FaceDetection.getClient(highAccuracyOpts)
val result = detector.process(image)
.addOnSuccessListener { faces ->