I have xamarin.forms android project app with a custom camera view. I am using Camera.IFaceDetectionListener
for detecting faces in the camera preview. It works fine on most of the devices. But in certain devices it throws exception which says invalid face detection type=0
after calling
Control.Preview.SetFaceDetectionListener(this);
Control.Preview.StartFaceDetection();
After some googling saw some SO post says some devices does not support face detection.
From this post Face detection not working , there is a way to check a device whether it support face detection or not by using Camera.getMaxNumDetectedFaces()
. How exactly can I use this in xamarin? Or is there any other way to solve this issue? Because my app gets crashed when starting the Face detection. Any help is appreciated.
Determine if the device supports facial recognition.
You could try to use this before you StartFaceDetection();
CameraManager cManager = (CameraManager)GetSystemService(Context.CameraService);
string cId = (int)CameraFacing.Front + "";
CameraCharacteristics cameraCharacteristics = cManager.GetCameraCharacteristics(cId);
int maxCount = (int)cameraCharacteristics.Get(CameraCharacteristics.StatisticsInfoMaxFaceCount);
If maxCount = 0
then we can be sure that our device does not support face detection