【发布时间】:2017-05-19 00:12:33
【问题描述】:
我找到了用于瞳孔检测的 Github 代码Pupil Detection with Python and OpenCV,它解释了如何检测眼睛瞳孔,但只解释了一只眼睛。我想检测两只眼睛。请告诉我如何从代码中检测双眼瞳孔。
谢谢
【问题讨论】:
标签: python-2.7 opencv computer-vision eye-detection
我找到了用于瞳孔检测的 Github 代码Pupil Detection with Python and OpenCV,它解释了如何检测眼睛瞳孔,但只解释了一只眼睛。我想检测两只眼睛。请告诉我如何从代码中检测双眼瞳孔。
谢谢
【问题讨论】:
标签: python-2.7 opencv computer-vision eye-detection
简要查看该代码,它看起来好像找到了两只眼睛,但只给了你一只。只需根据需要修改代码以提取两个找到的 blob,而不仅仅是一个。第 55-72 行是将您的候选池从一些 blob(可能的学生)修剪到 1。
所有这些行:“if len(contours) >= n”基本上是在说,如果你还有不止一个斑点,试着剪掉一个。问题是,你想要两个最大的斑点,而不是一个。因此,您需要重写这些检查语句,以便消除除了两个最大的斑点之外的所有斑点,然后在它们的每个质心上绘制圆圈。据我所知,其他都不需要修改。
这里有一些示例代码(未经测试)可能会有所帮助。 我不知道 python 语法,只是从你的链接文件中修改了一些东西:
while len(contours) > 2:
#find smallest blob and delete it
minArea = 1000000 #this should be the dimensions of your image to be safe
MAindex = 0 #to get the unwanted frame
currentIndex = 0
for cnt in contours:
area = cv2.contourArea(cnt)
if area < minArea:
minArea = area
MAindex = currentIndex
currentIndex = currentIndex + 1
del contours[MAindex] #remove the picture frame contour
del distanceX[MAindex]
这将使您找到两个眼睛斑点,然后您仍然需要为每个斑点中心添加一个圆形绘图。 (你需要删除所有的“if len...”语句并用这个while语句替换它们)
【讨论】: