如何在虹膜周围检测并画出一个圆圈? [英] How to detect and draw a circle around the iris?

查看:84
本文介绍了如何在虹膜周围检测并画出一个圆圈?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图检测眼睛的虹膜区域,然后在检测到的区域周围绘制一个圆圈。我设法使用阈值功能获得仅包含瞳孔,上眼睑线和眉毛的清晰的黑白眼睛图像。



一旦达到此目的,HoughCircles将用于检测图像中是否出现圆圈。但是,它从未检测到任何圆形区域。阅读HoughCircles后,它表示霍夫梯度法的工作原理如下: -



首先,图像需要通过边缘检测阶段(在本例中为cvCanny()) 。然后在阈值功能之后添加了一个精确的探测器。这仍然会产生零圆圈。如果我删除了阈值功能,眼睛图像会变得忙于不必要的线条,因此我把它包含在内。



   cv :: equalizeHist(grey,img); 
medianBlur(img,img, 1 );

IplImage img1 = img;
cvAddS(& img1,cvScalar( 70 70 70 ),& img1);
// 将IplImage转换为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>界;
/// 应用Hough变换查找圆圈
HoughCircles(imgg) ,圆圈,CV_HOUGH_GRADIENT, 1 ,imgg.rows / 8, 100 30 1 5 );



我怎样才能解决这个问题?霍夫圈方法是否有效?检测虹膜区域是否有更好的解决方案?选择的参数是否正确?



另请注意,图像是从网络摄像头直接获得的。

解决方案

我在检测琼脂培养皿中培养的培养物时尝试了Hough功能 - 不完全不同的东西 - 但放弃它并使用cvFindCountours代替。我看到我写了一个使用Canny的方法,但是我找不到Canny和Hough一起使用的任何地方。轮廓替代可能是有意义的:

  //  创建与图像m_imgEdgeDetected相同大小的IPL图像(标题和数据) 
IplImage * imgContoured = cvCreateImage(cvGetSize(_imgInput), 8 1 );

// 创建与图像大小相同的第二个IPL图像(标题和数据) m_imgEdgeDetected
IplImage * imgThresholded = cvCreateImage(cvGetSize(_imgInput), 8 1 );

// 将固定级阈值应用于灰度图像。这是一个应用的基本操作
// 在检索轮廓之前 - 不确定这是否有任何正在使用的效果
// 但确保传入的任何灰度图像都是阈值。
cvThreshold(_imgInput,imgThresholded, 1 255 ,CV_THRESH_BINARY) ;

// 创建新的内存存储。 Block_size == 0表示使用默认的,稍微优化的大小
// ,它是64K)。
CvMemStorage * storage = cvCreateMemStorage( 0 );

CvSeq * contour = 0 ;

// 检索白色(非零)连接组件的外边界和可选内边界
// 黑色(零)背景
cvFindContours( imgThresholded,storage和& contour, sizeof (CvContour),CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE);

// 清除所有数组元素(将它们设置为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 );
/ * 将CV_FILLED替换为1以查看轮廓* /
if (r.height< _nHeight&& r.width< _nHeight)
{
// cvDrawContours(imgThresholded,contour,color,color,-1,CV_FILLED,8);
cvDrawContours(imgContoured,contour,color,颜色, - 1 ,CV_FILLED, 8 );
}
}
// cvClearSeq(contour);
// 这需要吗?
cvReleaseMemStorage(& storage);


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.

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.

解决方案

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:

// 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);


这篇关于如何在虹膜周围检测并画出一个圆圈?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆