Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Iris detection using opencv
 

Iris detection using opencv

Hi

My final year project is on iris recognition. My code is supposed to display an image of an iris from file and then use circle finder to detect the edges around the iris and the pupil. However, i keep getting errors and am remaining with two weeks til the deadline. Any help?

#define CV_HOUGH_STANDARD 0

#define CV_HOUGH_PROBABILISTIC 1

#define CV_HOUGH_MULTI_SCALE 2

#define CV_HOUGH_GRADIENT 3

#define cvDrawCircle cvCircle

#include "cv.h" //main OpenCV functions

#include "highgui.h" //OpenCV GUI functions¯include <stdio.h>

#include "cxcore.h"

#include "cvaux.h"

#include "cvcam.h"

int main()

{

/* declare a new IplImage pointer, the basic

image data structure in OpenCV */

IplImage* newImg;

/* load an image named "0001.pgm", 1 means

this is a color image */

newImg = cvLoadImage("0001.pgm",1);

//create a new window

cvNamedWindow("Window", 1);

cvResizeWindow("Window",50,50);

//display the image in the window

cvShowImage("Window", newImg);

/* Finds circles in the image */

CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage,

int method, double dp, double min_dist,

double param1 CV_DEFAULT(100),

double param2 CV_DEFAULT(100),

int min_radius CV_DEFAULT(0),

int max_radius CV_DEFAULT(0));

//wait for key to close the window

cvWaitKey(0);

cvDestroyWindow( "Window" ); //destroy the window

cvReleaseImage( &newImg ); //release the memory for the image

return 0;

}

--------------------Configuration: IrisRecognition - Win32 Debug--------------------

Compiling...

IrisRecognition.c

c:\program files\microsoft visual studio\myprojects\irisrecognition\irisrecognition.c(39) : error C2275: 'CvSeq' : illegal use of this type as an expression

c:\program files\opencv\cxcore\include\cxtypes.h(1219) : see declaration of 'CvSeq'

c:\program files\microsoft visual studio\myprojects\irisrecognition\irisrecognition.c(39) : error C2059: syntax error : '__cdecl'

Error executing cl.exe.

IrisRecognition.obj - 2 error(s), 0 warning(s)

am using microsoft Visual C++ 2006

Thanks
JMukiibi  Monday, April 21, 2008 12:52 PM
Hi,

My end-of-study work is about gaze tracking, and I also have to perform iris detection (among other steps). I'm also using OpenCV .

Have you done any C before working on your project? You should practice or read some tutorials because your mistake seems very obvious:

/* Finds circles in the image */

CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage,

int method, double dp, double min_dist,

double param1 CV_DEFAULT(100),

double param2 CV_DEFAULT(100),

int min_radius CV_DEFAULT(0),

int max_radius CV_DEFAULT(0));



... this could not work. A call to a function in C is of the form "function(arg1, arg2, ...);" and what you wrote is a declaration of function, that is of the form "retType function(arg1Type arg1, arg2Type arg2, ...);" ...



Try :


CvMemStorage* storage = cvCreateMemStorage(0);
cvSmooth( newImg, newImg, CV_GAUSSIAN, 9, 9 ); // smooth it, otherwise a lot of
// false circles may be detected
CvSeq* circles = cvHoughCircles( newImg, storage, CV_HOUGH_GRADIENT, 2,
newImg->height/4, 200, 100 );


thomash01  Thursday, April 24, 2008 11:57 PM
Hi,

My end-of-study work is about gaze tracking, and I also have to perform iris detection (among other steps). I'm also using OpenCV .

Have you done any C before working on your project? You should practice or read some tutorials because your mistake seems very obvious:

/* Finds circles in the image */

CVAPI(CvSeq*) cvHoughCircles( CvArr* image, void* circle_storage,

int method, double dp, double min_dist,

double param1 CV_DEFAULT(100),

double param2 CV_DEFAULT(100),

int min_radius CV_DEFAULT(0),

int max_radius CV_DEFAULT(0));



... this could not work. A call to a function in C is of the form "function(arg1, arg2, ...);" and what you wrote is a declaration of function, that is of the form "retType function(arg1Type arg1, arg2Type arg2, ...);" ...



Try :


CvMemStorage* storage = cvCreateMemStorage(0);
cvSmooth( newImg, newImg, CV_GAUSSIAN, 9, 9 ); // smooth it, otherwise a lot of
// false circles may be detected
CvSeq* circles = cvHoughCircles( newImg, storage, CV_HOUGH_GRADIENT, 2,
newImg->height/4, 200, 100 );


thomash01  Thursday, April 24, 2008 11:57 PM

hi,

i tried the code given above on live video camera to detect circles.

0 error when i compiled the code but thenit return openCV GUI error handler when i executed the code.

it stated bad argument (the source image mustbe 8-bit, single channel)in function cvHoughCircles.

Howto change the image to be 8 bit?

Harris68  Tuesday, June 17, 2008 10:36 AM
Hi,

Indeed, when you give arguments of wrong type to a function, usually you can compile but there is no chance that you can run it after that whithout an error to occur. This is simply a kind of error that most of C/C++ compilers are not able to handle (or do not want to). Thus this is not particular to OpenCV libraries or functions, but rather to compilation softwares.

Here you need an image coded on 8 bits. As stated in OpenCV reference manual, the conventional range for R,G,B channel values is:
  • 0..255 for 8-bit images
  • 0..65535 for 16-bit images and
  • 0..1 for floating-point images.
You probably gave a 16-bit or a floating-point image in place of an 8-bit one. Thus two possibilities:
  • re-write all your code, replacing the occurences of the 16-bit (say) image by an 8-bit one; maybe you just need to change the declaration; for example the replacing declaration of your image could be

    IplImage *img = cvCreateImage(cvSize(200,200), IPL_DEPTH_8U, 3);

    or
  • convert your 16-bit (say) image to an 8-bit one; the piece of code should look like this:

    IplImage *img = cvCreateImage(cvSize(200,200), IPL_DEPTH_16S, 3);
    ...
    IplImage *img2 = cvCreateImage(cvSize(200,200), IPL_DEPTH_8U, 3);
    cvConvertScaleAbs(img, img2, 1, 0);

Finally, the best thing to do is perhaps to dive a little deeper in the reference manuals... ;-)

Regards

P.S. One more thing: because you need a single channel image, you should perform the additional conversion from BGR color space to gray. This is done similarly as above but with a single-channel destination image and using the function void cvCvtColor( const CvArr* src, CvArr* dst, int code ); with code CV_BGR2GRAY.

P.P.S. Simply take a look at this :-)

Example. Detecting circles with Hough transform.

#include <cv.h>
#include <highgui.h>
#include <math.h>

int main(int argc, char** argv)
{
IplImage* img;
if( argc == 2 && (img=cvLoadImage(argv[1], 1))!= 0)
{
IplImage* gray = cvCreateImage( cvGetSize(img), 8, 1 );
CvMemStorage* storage = cvCreateMemStorage(0);
cvCvtColor( img, gray, CV_BGR2GRAY );
cvSmooth( gray, gray, CV_GAUSSIAN, 9, 9 ); // smooth it, otherwise a lot of false circles may be detected
CvSeq* circles = cvHoughCircles( gray, storage, CV_HOUGH_GRADIENT, 2, gray->height/4, 200, 100 );
int i;
for( i = 0; i < circles->total; i++ )
{
float* p = (float*)cvGetSeqElem( circles, i );
cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), 3, CV_RGB(0,255,0), -1, 8, 0 );
cvCircle( img, cvPoint(cvRound(p[0]),cvRound(p[1])), cvRound(p[2]), CV_RGB(255,0,0), 3, 8, 0 );
}
cvNamedWindow( "circles", 1 );
cvShowImage( "circles", img );
}
return 0;
}

thomash01  Tuesday, June 17, 2008 11:38 AM

hi, many thanks for your explainantion :-)

now i can use cvHoughCircles without any problem. igrabbed someimages from running frame and playing with variables of cvsmooth and cvsobel. However i keep gettinginconsistency and worse, sometimes unnecessary circlesalso in the loop.. any way to detect correct circle? should i include other edge detection method besides cvsobel?

Thank you..

Harris68  Monday, June 23, 2008 10:46 AM
Hi, hey i'm also doing irisi recognition project with OpenCV. The problem is that i'm totally new to OpenCV and I don't have much time to do this project. Please can you send me your codes and tell me which algo you've used please? I really need your help. Thanks
VShwet  Monday, February 02, 2009 2:52 PM

You can use google to search for other answers

Custom Search

More Threads

• BackColor attribute doesn't affect changes
• DesignerHosting C# Sample as VB Solution
• Loading ToolstripButton Images from another component ( rather than from Resource )
• How does the designer locate an assembly ?
• Application Visual Style
• How to add controls at run-time ?
• Icons
• Name Property
• What is Regular Expression for US Phone Number(Windows application)?
• Problem to save collection property [VB.NET]