如何修改此代码以提高检测眼睛注视/瞳孔的稳定性?在低光下,这段代码的表现非常糟糕

时间:2019-02-16 03:50:58

标签: python python-3.x opencv hough-transform

我正在使用霍夫圆变换来检测瞳孔。如果有任何阴影或微弱的光线,它会检测到眼睛周围异常的圆圈。我尝试了几种过滤器,但效果不佳。

我尝试了高斯模糊,中值模糊和模糊来减少噪点,但没有得到太多结果。

import numpy as np
import cv2
cap = cv2.VideoCapture(1)

count=0

while True:
    # Capture frame-by-frame
    _, frame = cap.read()
    roi = frame[0: 480, 0: 840]
    cv2.imshow("roi",roi)
    cimg = cv2.cvtColor(roi, cv2.COLOR_BGR2HSV)
    lower_black = np.array([0, 0, 0])
    upper_black = np.array([180, 255, 50])
    mask = cv2.inRange(cimg, lower_black, upper_black)
    mask = cv2.blur(mask,(9,9),0)
    # mask = cv2.medianBlur(mask,)



#circles = cv2.HoughCircles(cimg,cv2.HOUGH_GRADIENT,1,300,param1=300,param2=20,minRadius=10,maxRadius=40)
# circles = cv2.HoughCircles(grey,cv2.HOUGH_GRADIENT,minDist=30,minRadius=0,maxRadius=0)
#circles = cv2.HoughCircles(cimg,cv2.HOUGH_GRADIENT,100,200)
circles = cv2.HoughCircles(mask,cv2.HOUGH_GRADIENT,1,300,param1=300,param2=20,minRadius=10,maxRadius=40) 


if circles is None:
    cv2.imshow("roi",mask)
    print ("Not Found")
    continue     

a =circles.tolist()

lst1=[item[0] for item in a[0]]
lst2=[item[1] for item in a[0]]

i=0
left_x=0
right_x=0

while i < len(lst1):
    if (i==0):
        left_x=lst1[i]
    if (i==1):
        right_x=lst1[i]
    i=i+1

i=0
left_y=0
right_y=0

while i < len(lst2):
    if (i==0):
        left_y=lst2[i]
    if (i==1):
        right_y=lst2[i]
    i=i+1

print("whole List")
print(a)
print("Left_X",left_x)
print("Right_X",right_x)
print("Left_y",left_y)
print("Right_y",right_y)




for i in circles[0,:]:
    cv2.circle(mask,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
    cv2.circle(mask,(i[0],i[1]),2,(0,0,255),3)


# Display the resulting frame
cv2.imshow('hsv',mask)
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

我想发现学生。圆圈必须稳定。

0 个答案:

没有答案