Iris Detection

asked 2013-06-17 02:55:27 -0500

Amit Dev gravatar image

updated 2013-06-17 09:29:18 -0500

Hi, I'am using the following code for Iris Detection. Apparently the code for hough circles thatI picked up from this website http://opencvlover.blogspot.in/2012/07/hough-circle-in-javacv.html for cvsmooth, cvthreshold, cvhoughcircles is not working. The code that I'am using is the following. It doesn't give a compilation error. But it doesn't detect the iris/circle either. Could someone please help me out

package com.googlecode.javacv.eyepreview;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ImageFormat;
import android.graphics.Paint;
import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.os.Bundle;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.FrameLayout;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import com.googlecode.javacpp.Loader;
import com.googlecode.javacv.cpp.opencv_core.CvSeq;
import com.googlecode.javacv.cpp.opencv_core.IplImage;
import com.googlecode.javacv.cpp.opencv_objdetect;

import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_objdetect.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;

// ----------------------------------------------------------------------

public class EyePreview extends Activity {
    private FrameLayout layout;
    private EyeView eyeView;
    private Preview mPreview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        // Hide the window title.
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        // Create our Preview view and set it as the content of our activity.
        try {
            layout = new FrameLayout(this);
            eyeView = new EyeView(this);
            mPreview = new Preview(this, eyeView);
            layout.addView(mPreview);
            layout.addView(eyeView);
            setContentView(layout);
        } catch (IOException e) {
            e.printStackTrace();
            new AlertDialog.Builder(this).setMessage(e.getMessage()).create().show();
        }
    }
}

// ----------------------------------------------------------------------

class EyeView extends View implements Camera.PreviewCallback {
    public static final int SUBSAMPLING_FACTOR = 4;

    private IplImage grayImage, grayImage1;
    private CvHaarClassifierCascade classifier;
    private CvMemStorage storage, mem;
    private CvSeq eyes;

    public EyeView(EyePreview context) throws IOException {
        super(context);

        // Load the classifier file from Java resources.
        File classifierFile = Loader.extractResource(getClass(),
            "/com/googlecode/javacv/eyepreview/haarcascade_eye.xml",
            context.getCacheDir(), "classifier", ".xml");
        if (classifierFile == null || classifierFile.length() <= 0) {
            throw new IOException("Could not extract the classifier file from Java resource.");
        }

        // Preload the opencv_objdetect module to work around a known bug.
        Loader.load(opencv_objdetect.class);
        classifier = new CvHaarClassifierCascade(cvLoad(classifierFile.getAbsolutePath()));
        classifierFile.delete();
        if (classifier.isNull()) {
            throw new IOException("Could not load the classifier file.");
        }
        storage = CvMemStorage.create();

    }

    public void onPreviewFrame(final byte[] data, final Camera camera) {
        try {
            Camera.Size size = camera.getParameters().getPreviewSize();
            processImage(data, size.width, size.height);
            camera.addCallbackBuffer(data);
        } catch (RuntimeException e) {
            // The camera has probably just been released, ignore.
        }
    }

    protected void processImage(byte[] data, int width, int height) {
        // First, downsample our image and convert it into a grayscale IplImage
        int f = SUBSAMPLING_FACTOR;
       /* if (grayImage == null || grayImage.width() != width/f || grayImage.height() != height/f) {
            grayImage = IplImage.create(width/f, height/f, IPL_DEPTH_8U, 1);
        }
        int imageWidth  = grayImage.width();
        int imageHeight = grayImage.height();
        int dataStride = f*width;
        int imageStride = grayImage.widthStep();
        ByteBuffer imageBuffer ...
(more)
edit retag flag offensive close merge delete

Comments

This is a Q&A forum, we're not here to solve problems of people that haven't at least tried solving it themselves!

Notas gravatar imageNotas ( 2013-06-17 04:50:12 -0500 )edit

I have tried a lot. Please someone help

Amit Dev gravatar imageAmit Dev ( 2013-06-17 09:50:33 -0500 )edit
1

No one is going to look through your hundreds of LOC. Ask specific questions on one single area in your detection and we will try to help. But a simple "doesn't work" won't cut it.

Notas gravatar imageNotas ( 2013-06-17 10:57:07 -0500 )edit

consider to discard the idea of finding the iris outline using houghcircles, it's very picky about circles being "perfect". though it might work nicely for the 'pupil' ( the inner black spot ), the iris itself is 99% of the times partly occluded by the eyelids.

(and, no, i did not read your android specific code at all )

berak gravatar imageberak ( 2013-06-17 13:41:30 -0500 )edit

I have tried to debug the code but i get stuck at the following piece of code:

if (grayImage1 == null || grayImage1.width() != width/f || grayImage1.height() != height/f) -breakpoint-----grayImage1 = IplImage.create(width/f, height/f, IPL_DEPTH_8U, 1);

if I try to step over it it gives:

public NoClassDefFoundError(String detailMessage) { super(detailMessage); }

and gets stuck in a loop

Amit Dev gravatar imageAmit Dev ( 2013-06-18 03:09:31 -0500 )edit