1

我正在使用pythonwith opencv包从图像中寻找瞳孔检测。在我的测试图像中,我能够在 (a) 部分检测到瞳孔,但只要存在反射/眩光,我就无法blob在图像的 (b) 部分准确检测到瞳孔像素。有人可以帮帮我吗?这是我正在尝试的代码。测试图像

import numpy as np
import cv2

name = 'two_eyes1.png'

# reading an image
img = cv2.imread(name, cv2.IMREAD_COLOR)

# inverting image
img_inv = cv2.bitwise_not(img)

gray = cv2.cvtColor(img_inv, cv2.COLOR_BGR2GRAY)

ret, threshold = cv2.threshold(gray, 225, 255, cv2.THRESH_BINARY)

#----- Blob detector parameters initiation
params = cv2.SimpleBlobDetector_Params()
#change thresholds
params.minThreshold = 0;
params.maxThreshold = 255;
#filter by area
params.filterByArea = True
params.minArea = 70
# filter by cicularity
params.filterByCircularity = True
params.minCircularity = 0.1
# filter by convexity
params.filterByConvexity = True
params.minConvexity = 0.87
# filter by inertia
params.filterByInertia = True
params.minInertiaRatio = 0.01

det = cv2.SimpleBlobDetector_create(params)

keypoints = det.detect(img)

im_with_key = cv2.drawKeypoints(img, keypoints, np.array([]),
            (0,0,255),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
#----------

titles = ['Input','Inverted','Grayscaled','Thresholded','blobpart']
images = [img, img_inv, gray, threshold, im_with_key]

for i in range(5):
    cv2.imshow(titles[i], images[i])
cv2.waitKey(0)
cv2.destroyAllWindows()
4

0 回答 0