Capture Image on Eye Blink

Capture Image on Eye Blink

The Mobile Vision API provides a framework for recognizing objects in photos and videos. The framework includes detectors, which locate and describe visual objects in images or video frames, and an event-driven API that tracks the position of those objects in video.

The objects that can be tracked by Mobile Vision API include facial features, text and bar codes.

For our purpose, we will be doing real-time tracking of face objects using a custom camera. So let’s get started.

First, create a new project and add the following dependencies in your app level build.gradle file which is available at location: app/build.gradle.

Now open strings.xml file at location res/values/strings.xml and add the following in it.

Now let’s build our layout file. So open activity_main.xml file and add the below code.

Here SurfaceView is used for the camera instance that we will be creating in the latter part of this post.

Now in the MainActivity.java, add the below code

Here we create a custom Tracker, i.e, GraphicFaceTracker which tracks the facial features. We use this to track the blinking of the eyes.

Below is the code for GraphicFaceTracker.java.

Now once the image has been clicked, we display it in the PictureActivity.java.

Below is the code for activity_picture.xml.

And the code for PictureActivity.java is below.

Now on running this code, we can see that on blinking our eyes, an image will be captured and displayed.

You can also read our blog on the topic Custom Camera using SurfaceView“.

InnovationM is a globally renowned Mobile app development company that caters to a strong & secure Android app development, iOS app development, hybrid app development services. Our commitment & engagement towards our target gives us brighter in the world of technology and has led us to establish success stories consecutively which makes us the best iOS app development company.

That’s all for this post. Hope you enjoyed learning. 🙂

Leave a Reply