Eye Blink Detection in flutter?

Viewed 1898

Can't find any implementation/package anything related blink detection in flutter, if anyone implemented please share. Eye blink detection in flutter any package idea? or I have to do it in native? any suggestion will be appreciated. Thanks

3 Answers

You can use Python's OpenCV package along many others to detect eye movements/blinking and then integrate it with flutter

Once you consume the video feed,

EYE_AR_THRESH = 0.3   

for rect in rects:
    # determine the facial landmarks for the face region, then
    # convert the facial landmark (x, y)-coordinates to a NumPy
    # array
    shape = predictor(gray, rect)
    shape = face_utils.shape_to_np(shape)
    # extract the left and right eye coordinates, then use the
    # coordinates to compute the eye aspect ratio for both eyes
    leftEye = shape[lStart:lEnd]
    rightEye = shape[rStart:rEnd]
    # EAR = eye aspect ratio
    leftEAR = eye_aspect_ratio(leftEye)                     # important line
    rightEAR = eye_aspect_ratio(rightEye)                   # important line
    # average the eye aspect ratio together for both eyes
    ear = (leftEAR + rightEAR) / 2.0

The var 'ear' gives eye aspect ratio. Now, you compare if it is below the threshold.

if ear < EYE_AR_THRESH:
    # eye is blinked. continue with your business logic.

I do think this would be the easiest and most effective method

For more info please visit this tutorial on eye-tracking.

You can find/train a Tensor Flow model and convert it into a .tflite model along with a .txt file which contains the list of classes.

You can then use tflite package to use model.

For getting the results from image stream Use it with the camera 0.5.8+2 plugin.

await cameraController.startImageStream((CameraImage img) {
    var recognitions = await Tflite.runModelOnFrame(
    bytesList: img.planes.map((plane) {return plane.bytes;}).toList(),// required
    imageHeight: img.height,
    imageWidth: img.width,
    imageMean: 127.5,   // defaults to 127.5
    imageStd: 127.5,    // defaults to 127.5
    rotation: 90,       // defaults to 90, Android only
    numResults: 2,      // defaults to 5
    threshold: 0.1,     // defaults to 0.1
    asynch: true        // defaults to true
    );

print(recognitions);
}

For flutter, I found solution for eye blink detection through using Firebase ML. for this I had to use this package

It has face detector feature which include 'eye open probability'. Thus solve the problem. For details check the package.

FirebaseVision.instance.faceDetector().processImage

You can check package and its example through git repo.

comment here if anyone face any problem.

Related