简体   繁体   English

使用 Python / OpenCV 将圆圈拟合到虹膜照片

[英]Fitting circle to photo of iris using Python / OpenCV

I've got a lot of frontal face images, and I want to obtain the exact position of the (center of the) two irises in these pictures.我有很多正面图像,我想获得这些图片中两个虹膜(中心)的确切 position。 For example:例如:

在此处输入图像描述 , , 在此处输入图像描述 , , 在此处输入图像描述

I have already run the DLib 68 landmark face annotator to get the position of the two eyes, so for example I would have a picture that looks like this:我已经运行了 DLib 68 landmark face annotator 来获得两只眼睛的 position,所以例如我会有一张看起来像这样的图片:

眼睛的照片 , , 在此处输入图像描述 , , 在此处输入图像描述

As can be seen, the annotation is able to get the rough position of the eye correct.可以看出,注释能够得到眼睛正确的粗略position。 I have already tried to follow the approach in this article , but this requires the lighting conditions in all pictures to be the same and the threshold to be manually set.我已经尝试过按照本文的方法,但这需要所有图片的光照条件相同,并且需要手动设置阈值。 Also, the convex polygon around the eye is not always complete, so this won't work, as it will sometimes only have part of the eye inside the mask:此外,眼睛周围的凸多边形并不总是完整的,所以这不起作用,因为它有时只有部分眼睛在蒙版内:

keypoints = [36, 37, 38, 39, 40, 41]
landmarks = image.get_face_landmarks()
points = np.array([landmarks[i] for i in keypoints], dtype=np.int32)

mask = np.zeros(img.shape[:2], dtype=np.uint8)
mask = cv2.fillConvexPoly(mask, points, 255)
    
mask = cv2.dilate(mask, np.ones((9,9)))
eyes = cv2.bitwise_and(img, img, mask=mask)
eyes[(eyes == 0).all(2)] = [255, 255, 255]
eyes_gray = cv2.cvtColor(eyes, cv2.COLOR_BGR2GRAY)

I was thinking of using something like Hough circle transform, but for that I would need the whole iris to be fully visible, not covered partly by an eyelid.我正在考虑使用霍夫圆变换之类的东西,但为此我需要整个虹膜完全可见,而不是被眼睑部分覆盖。 As the iris is a partly circular shape, and is surrounded by a very different color inside the eye, I figured it should be possible to fit a circle to the iris, how would I best approach this?由于虹膜是部分圆形的,并且在眼睛内部被一种非常不同的颜色所包围,我认为应该可以在虹膜上放置一个圆圈,我该如何最好地解决这个问题? This answer suggests using the landmarks and contours, but so far I haven't gotten that working reliably.这个答案建议使用地标和轮廓,但到目前为止我还没有得到可靠的工作。

The article and paper proposed by Diego Schmaedech in the comments indeed provides a good way to fix this, I have found an implementation here which yields accurate results with good performance Diego Schmaedech 在评论中提出的文章和论文确实提供了解决此问题的好方法,我在这里找到了一个实现,它可以产生准确的结果和良好的性能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM