Face and Eye detection in android

asked 2015-01-19 07:14:27 -0500

Vishal Chhatwani gravatar image

Hello everyone. What I want to do is to detect the yawning and blinking of eyes. So far I have just been able to create a videoview and displayed a camera preview on that videoview. Now I need to apply some techniques like haar cascade or some other to detect the eyes and face. I have been looking all over internet but couldnt find exact solution. Can someone please tell me an easy solution to this.

This is the code of my CameraPreview class so far.

public class CameraPreview extends Activity implements SurfaceHolder.Callback{

    private VideoView videoView = null;
    private SurfaceHolder holder = null;
    private Camera camera = null;
    private static final String TAG = "Video";
    private int cameraId;
    protected void onCreate(Bundle savedInstanceState) {
        cameraId = getFrontCameraId();
        try {

            camera = Camera.open(cameraId);
        } catch(RuntimeException re) {
            Log.v(TAG, "Could not initialize the Camera");

        videoView = (VideoView) this.findViewById(R.id.videoView);
        holder = videoView.getHolder();

    private int getFrontCameraId(){
        int camId = -1;
        int numberOfCameras = Camera.getNumberOfCameras();
        CameraInfo ci = new CameraInfo();

        for(int i = 0;i < numberOfCameras;i++){
            if(ci.facing == CameraInfo.CAMERA_FACING_FRONT){
                camId = i;

        return camId;

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;

    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        return super.onOptionsItemSelected(item);
    public void surfaceCreated(SurfaceHolder holder) {
        // TODO Auto-generated method stub
         Log.v(TAG, "in surfaceCreated");

            try {
            } catch(IOException e) {
                Log.v(TAG, "Could not start the preview");
    public void surfaceChanged(SurfaceHolder holder, int format, int width,
            int height) {
        // TODO Auto-generated method stub

    public void surfaceDestroyed(SurfaceHolder holder) {
        // TODO Auto-generated method stub

Thanks in advance :)

edit retag flag offensive close merge delete



please only post code that is somehow related to your problem!

FooBar gravatar imageFooBar ( 2015-01-19 07:30:31 -0500 )edit

I thought this is related to my problem because the additional code will be related to this class. I could not find any useful code on eye detection in android. So I am really waiting for someone who can help me with this. :)

Vishal Chhatwani gravatar imageVishal Chhatwani ( 2015-01-19 07:41:23 -0500 )edit