当我使用Hough变换时,我遇到了问题。我想检测虹膜图像中唯一的瞳孔。代码如下:
import cv2
from cv2 import cv
import numpy as np
import os
directory = os.listdir("/home/joker26/Scrivania/casia/test")
numero_file = len(directory)
for file in directory:
print file
file_iride = raw_input("File(riportare anche estensione): ")
path = "/home/joker26/Scrivania/casia/test/%s" %(file_iride)
image_iride = cv2.imread(path)
output = image_iride.copy()
image_test = cv2.imread(path, cv2.CV_LOAD_IMAGE_GRAYSCALE)
image_test = cv2.Canny(image_test,5,70,apertureSize=3)
image_test = cv2.GaussianBlur(image_test, (7,7), 1)
cerchi = cv2.HoughCircles(image_test, cv2.cv.CV_HOUGH_GRADIENT,50, 100, 50,300)
if cerchi is not None:
cerchi = np.round(cerchi[0,:]).astype("int")
for (x,y,raggio) in cerchi:
cv2.circle(output, (x,y),raggio,(255,0,0),4)
cv2.imshow("Image test", np.hstack([image_iride,output]))
cv2.waitKey()
import cv2
from cv2 import cv
import numpy as np
import os
directory = os.listdir("/home/joker26/Scrivania/casia/test")
numero_file = len(directory)
for file in directory:
print file
file_iride = raw_input("File(riportare anche estensione): ")
path = "/home/joker26/Scrivania/casia/test/%s" %(file_iride)
image_iride = cv2.imread(path)
output = image_iride.copy()
image_test = cv2.imread(path, cv2.CV_LOAD_IMAGE_GRAYSCALE)
image_test = cv2.Canny(image_test,5,70,apertureSize=3)
image_test = cv2.GaussianBlur(image_test, (7,7), 1)
cerchi = cv2.HoughCircles(image_test, cv2.cv.CV_HOUGH_GRADIENT,50, 100, 50,300)
if cerchi is not None:
cerchi = np.round(cerchi[0,:]).astype("int")
for (x,y,raggio) in cerchi:
cv2.circle(output, (x,y),raggio,(255,0,0),4)
cv2.imshow("Image test", np.hstack([image_iride,output]))
cv2.waitKey()
结果是:
http://i.stack.imgur.com/LJOE9.png
答案 0 :(得分:0)
检测瞳孔而不是虹膜有什么意义?它们都是眼睛的一部分。但是,您的错误在于测试数据。
您正在使用的测试数据,我认为是数千张人眼的照片。现在,您的计算机将学会识别这些照片中的内容,如果您的训练数据是全眼睛,它将显示全眼睛。该缺陷不在您的代码中,而是在您的代码正在访问的数据中。
答案 1 :(得分:0)
您可以使用:
cerchi = cv2.HoughCircles(image_test, cv2.HOUGH_GRADIENT, 1.3, 800)