Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more: , +
I have been trying to detect the iris region of an eye and thereafter draw a circle around the detected area.I have managed to obtain a clear black and white eye image containing just the pupil,upper eyelid line and eyebrow using threshold function.

Once this is achieved HoughCircles is applied to detect if there are circles appearing in the image.However, it never detects any circular regions.After reading up on HoughCircles,it states that "the Hough gradient method works as follows:-

First the image needs to be passed through an edge detection phase (in this case, cvCanny())".I then added a canny detector after the threshold function.This still produced zero circles detected.If I remove the threshold function the eye image becomes busy with unnecessary lines,hence I included it in.

C++
cv::equalizeHist(gray,img);
medianBlur ( img,img,1);

IplImage img1=img;
cvAddS(&img1, cvScalar(70,70,70), &img1);
//converting IplImage to cv::Mat  
Mat imgg=cvarrToMat(&img1);

medianBlur ( imgg,imgg,1);
cv::threshold(imgg,imgg, 120,255,CV_THRESH_BINARY);
cv::Canny(img,img,0,20);

medianBlur ( imgg,imgg,1);

vector<Vec3f> circles;
/// Apply the Hough Transform to find the circles
HoughCircles( imgg, circles, CV_HOUGH_GRADIENT, 1, imgg.rows/8, 100, 30, 1,5);

How can I overcome this problem?Would hough circle method work?Is there a better solution to detecting the iris region?Are the parameters chosen correct?

Also note that the image is obtain directly obtained from the webcam.
Posted
Comments
The_Inventor 21-Jul-13 21:16pm    
When dealing with images, one needs to remember it is 2D pixel data. I think that color variance in the small region of the 'eye' would be more effective. Look for white pixels that might surround the colored area. I don't believe that your circle function is well enough adapted, to deal with squares, anti-aliased into some form of a ellipse, and not a circle.

1 solution

I tried the Hough function when detecting growing cultures within a petri-dish of agar - something not completely dissimilar - but gave up on it and used cvFindCountours instead. I see I've written a method to use Canny but couldn't find anywhere were I used Canny and Hough together. The contour alternative may be of interest:
C++
// Creates an IPL image (header and data) the same size as the image m_imgEdgeDetected
	IplImage* imgContoured = cvCreateImage( cvGetSize(_imgInput), 8, 1 );

	// Creates a second IPL image (header and data) the same size as the image m_imgEdgeDetected
	IplImage* imgThresholded = cvCreateImage( cvGetSize(_imgInput), 8, 1 );

	// Applies fixed-level threshold to grayscale image. This is a basic operation applied 
	// before retrieving contours - not sure this is having any effect as it is being used 
	// but would ensure any greyscale image passed in would be thresholded.
	cvThreshold( _imgInput, imgThresholded, 1, 255, CV_THRESH_BINARY );

	// Creates new memory storage. Block_size == 0 means that default, somewhat optimal size, 
	// is used (currently, it is 64K).
	CvMemStorage* storage = cvCreateMemStorage(0);

	CvSeq* contour = 0;

	// Retrieves outer and optionally inner boundaries of white (non-zero) connected components in the 
	// black (zero) background
	cvFindContours(imgThresholded, storage, &contour, sizeof(CvContour), CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE );
	
	// Clear all the array elements (sets them to 0)
	cvZero(imgThresholded );
	cvReleaseImage(&imgThresholded);

	cvZero(imgContoured );
	
	for( ; contour != 0; contour = contour->h_next )
	{
		CvRect      r = ((CvContour*)contour)->rect;
		CvScalar color = CV_RGB( 255,255,255);
		/* replace CV_FILLED with 1 to see the outlines */
		if(r.height < _nHeight && r.width < _nHeight)
		{		
//			cvDrawContours( imgThresholded, contour, color, color, -1, CV_FILLED, 8 );
			cvDrawContours( imgContoured, contour, color, color, -1, CV_FILLED, 8 );
		}
	}
//	cvClearSeq(contour);
	// Is this needed here?
	cvReleaseMemStorage(&storage);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900