1

Currently i am using ML Kit to detect face in my application. It's working but has one problem. I want to set minimum face size on it but it seems to have no effect. It always detects a face no matter what size is it.

Here is my code:

private fun setupCamera(cameraProviderFuture: ListenableFuture<ProcessCameraProvider>, mainView: MainView) {
    val cameraProvider = cameraProviderFuture.get()

    preview = Preview.Builder().build()

    val cameraSelector = CameraSelector.Builder().requireLensFacing(CameraSelector.LENS_FACING_FRONT).build()

    val realTimeOpts = FaceDetectorOptions.Builder()
        .setPerformanceMode(FaceDetectorOptions.PERFORMANCE_MODE_FAST)
        .setMinFaceSize(0.5f)
        .enableTracking()
        .build()

    detector = FaceDetection.getClient(realTimeOpts)

    val imageAnalysis = ImageAnalysis.Builder()
        .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
        .build()
        .apply { setAnalyzer(Executors.newSingleThreadExecutor(), FaceDetectAnalyzer(detector!!, mainView))}

    try {
        cameraProvider.unbindAll()

        camera = cameraProvider.bindToLifecycle(this as LifecycleOwner, cameraSelector, imageAnalysis, preview)
        preview?.setSurfaceProvider(binding.pvCameraPreview.createSurfaceProvider())
    } catch (e: Exception) {
        Log.e(TAG, "Use case binding failed", e)
    }
}

Could someone point me any clues or suggestions? Thank you.

Selmeny
  • 220
  • 3
  • 11

1 Answers1

3

It is the true, the image size is not a hard limitation, that is why we put the comment in the java doc.

"This is not a hard limit on face size; the detector may find faces slightly smaller than specified."

You could increase the minFaceSize if you only have interests in larger faces. Or you could do a filtering for the size in your end. By increasing the minFaceSize, the performance will be improved.

Shiyu
  • 875
  • 4
  • 5
  • 2
    Do you mean it's only related with performance? Because i tried to set it to max (1.0f) and it's still not working. It always detects face no matter how small is it. – Selmeny Aug 10 '20 at 01:39
  • 1
    Yes, right now it is mainly for performance boosts. We use it to decide the block size when scanning the image. It can not be used directly to filter out face sizes, which we could improve. If you do want to filter out small faces, you may need to filter out in the app size with the return bounding box size. – Shiyu Aug 10 '20 at 21:41
  • I see. So for now, i can filter it by using width of the bounding box size. Thank you. – Selmeny Aug 11 '20 at 03:01
  • @Shiyu why can't this explanation be there in the docs that it can not be used to filter out faces by sizes? – Devansh Maurya Aug 25 '20 at 10:10