【问题标题】:How to detect both eyes Pupil using Python and OpenCV如何使用 Python 和 OpenCV 检测双眼瞳孔
【发布时间】:2017-05-19 00:12:33
【问题描述】:

我找到了用于瞳孔检测的 Github 代码Pupil Detection with Python and OpenCV,它解释了如何检测眼睛瞳孔,但只解释了一只眼睛。我想检测两只眼睛。请告诉我如何从代码中检测双眼瞳孔。

谢谢

【问题讨论】:

    标签: python-2.7 opencv computer-vision eye-detection


    【解决方案1】:

    简要查看该代码,它看起来好像找到了两只眼睛,但只给了你一只。只需根据需要修改代码以提取两个找到的 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语句替换它们)

    【讨论】:

    • 当我更改为 1 时。我收到此错误:@SneakyPolarBear C:/Python27/Projects/proj/pupil.py:38: VisibleDeprecationWarning: using a non-integer number instead of an integer will导致将来出现错误学生Frame = cv2.equalizeHist(frame[y+(h*.25):(y+h), x:(x+w)]) Traceback(最近一次调用最后一次):文件“C: /Python27/Projects/proj/pupil.py",第 92 行,在 如果 len(largeBlob) > 0: NameError: name 'largeBlob' is not defined
    • 我不会用python编程,所以调试取决于你,但我认为你不理解我,所以我添加到我的答案中
    猜你喜欢
    • 2018-10-04
    • 1970-01-01
    • 2018-11-19
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    • 2013-12-30
    • 2017-06-05
    相关资源
    最近更新 更多