def findEllipseContour(img, gradientMagnitude, estimatedCenter, estimatedRadius,nPts=30):
    Gm=np.copy(gradientMagnitude)
    P= getCircleSamples(center=estimatedCenter,radius=estimatedRadius ,nPoints= nPts)
    samplePoints=[]
    #< define normalLength as some maximum distance away from initial circle >
    normalLength = 5
    P2=getCircleSamples(center=estimatedCenter,radius=estimatedRadius+normalLength,nPoints= nPts)
    normals=[]
    nPts = 30
    newPupil = np.zeros((nPts,1,2)).astype(np.float32)
    #< get the endpoints of the normal -> p1,p2>
    for (x,y,dx,dy) in P:
        p1 = (int(x),int(y))
        samplePoints.append(p1)
    for (x,y,dx,dy) in P2:
        p2 = (int(x),int(y))
        normals.append(p2)
    t=0
    for i in range(nPts):
        #< maxPoint= findMaxGradientValueOnNormal(gradientMagnitude,p1,p2) >
        maxPoint = findMaxGradientValueOnNormal(Gm,samplePoints[i],normals[i])
        #< store maxPoint in newPupil>
        newPupil[t]=maxPoint
        t=t+1
    #<fitPoints to model using least squares- cv2.fitellipse(newPupil)>
    ellipse = cv2.fitEllipse(newPupil)
    cv2.ellipse(Gm,ellipse,(0,255,0),1)
    cv2.imshow("TempResults", Gm) #display the gradients magnitude with pupilEllipseContour
    #return ellipseParameters
    return ellipse
예제 #2
0
def circleTest(img, center, radius, samples):
    P = getCircleSamples(center=center, radius=radius, nPoints=samples)
    t = 0
    for (xf, yf, dxf, dyf) in P:
        x, y, dx, dy = int(xf), int(yf), int(dxf * radius), int(dyf * radius)
        cv2.circle(img, (x, y), 2, (0, 255, 0), 4)
        cv2.line(img, (x - dx, y - dy), (x + dx, y + dy), (0, 255, 0))
예제 #3
0
def GetIrisUsingNormals(img, gray, pupils, normalLength):
    xIm, yIm, magIm, angleIm = getGradientImageInfo(gray)
    iris = []
    for ((pX, pY), pRad, pAng) in pupils:
        P = getCircleSamples(center=(pX, pY), radius=120, nPoints=50)
        irisPoints = []
        for (xf, yf, dxf, dyf) in P:
            maxGrad = 0
            maxPoint = (-1, -1)
            band = 40
            ix, iy, idx, idy = int(xf), int(yf), int(dxf * band), int(dyf *
                                                                      band)
            angle = math.atan2(dyf, dxf) * (180 / math.pi)
            maxX, maxY = magIm.shape
            for (x, y) in getLineCoordinates((ix - idx, iy - idy),
                                             (ix + idx, iy + idy)):
                if 0 < x < maxX and 0 < y < maxY and magIm[x][
                        y] > maxGrad and math.fabs(angleIm[x][y] - angle) > 45:
                    maxGrad = magIm[x][y]
                    maxPoint = (x, y)
            if maxGrad > 0:
                irisPoints.append(maxPoint)
        if len(irisPoints) > 5:
            iris.append(cv2.fitEllipse(np.array(irisPoints)))
    return iris
예제 #4
0
def circleTest(img, center, radius, samples):
    P = getCircleSamples(center=center, radius=radius, nPoints=samples)
    t = 0
    for (xf,yf,dxf,dyf) in P:
        x, y, dx, dy = int(xf), int(yf), int(dxf * radius), int(dyf * radius)
        cv2.circle(img,(x, y), 2, (0,255,0), 4)
        cv2.line(img, (x - dx, y - dy), (x + dx, y + dy), (0,255,0))
예제 #5
0
def circleTest(img, center_point):
	nPts = 20
	circleRadius = 100
	P = getCircleSamples(center=center_point, radius=circleRadius, nPoints=nPts)
	for (x,y,dx,dy) in P:
		point_coords = (int(x),int(y))
		cv2.circle(img, point_coords, 2, bgr_yellow, 2)
		cv2.line(img, point_coords, center_point, bgr_yellow)
예제 #6
0
def findEllipseContour(img,
                       gradientMagnitude,
                       estimatedCenter,
                       estimatedRadius,
                       nPts=30):
    Gm = np.copy(gradientMagnitude)
    P = getCircleSamples(center=estimatedCenter,
                         radius=estimatedRadius,
                         nPoints=nPts)
    samplePoints = []
    #< define normalLength as some maximum distance away from initial circle >
    normalLength = 5
    P2 = getCircleSamples(center=estimatedCenter,
                          radius=estimatedRadius + normalLength,
                          nPoints=nPts)
    normals = []
    nPts = 30
    newPupil = np.zeros((nPts, 1, 2)).astype(np.float32)
    #< get the endpoints of the normal -> p1,p2>
    for (x, y, dx, dy) in P:
        p1 = (int(x), int(y))
        samplePoints.append(p1)
    for (x, y, dx, dy) in P2:
        p2 = (int(x), int(y))
        normals.append(p2)
    t = 0
    for i in range(nPts):
        #< maxPoint= findMaxGradientValueOnNormal(gradientMagnitude,p1,p2) >
        maxPoint = findMaxGradientValueOnNormal(Gm, samplePoints[i],
                                                normals[i])
        #< store maxPoint in newPupil>
        newPupil[t] = maxPoint
        t = t + 1
    #<fitPoints to model using least squares- cv2.fitellipse(newPupil)>
    ellipse = cv2.fitEllipse(newPupil)
    cv2.ellipse(Gm, ellipse, (0, 255, 0), 1)
    cv2.imshow("TempResults",
               Gm)  #display the gradients magnitude with pupilEllipseContour
    #return ellipseParameters
    return ellipse
예제 #7
0
def simplifiedHough(edgeImage,circleCenter,minR,maxR,N,thr):
	samplePoints  = 200
	accumulator_line = {}

	for radius in range(minR, maxR, N):
		points = getCircleSamples(center=circleCenter, radius=radius, nPoints=samplePoints)
		accumulator_line[radius] = 0
		for point in points:
			try:
				if edgeImage[point[0], point[1]] > 0:
					accumulator_line[radius] += 1
			except IndexError:
				continue
	radii = []
	for radius in accumulator_line:
		value = accumulator_line[radius]
		if value > thr:
			radii.append(radius)
			print value
	return radii
예제 #8
0
def GetIrisUsingNormals(img, gray, pupils, normalLength):
	xIm, yIm, magIm, angleIm = getGradientImageInfo(gray)
	iris = []
	for ((pX, pY), pRad, pAng) in pupils:
		P = getCircleSamples(center = (pX, pY), radius=120, nPoints=50)
		irisPoints = []
		for (xf, yf, dxf, dyf) in P:
			maxGrad = 0
			maxPoint = (-1, -1)
			band = 40
			ix, iy, idx, idy = int(xf), int(yf), int(dxf * band), int(dyf * band)
			angle = math.atan2(dyf, dxf)* (180 / math.pi)
			maxX, maxY = magIm.shape
			for (x, y) in getLineCoordinates((ix - idx, iy - idy), (ix + idx, iy + idy)):
				if 0 < x < maxX and 0 < y < maxY and magIm[x][y] > maxGrad and math.fabs(angleIm[x][y] - angle) > 45:
					maxGrad = magIm[x][y]
					maxPoint = (x, y)
			if maxGrad > 0:
				irisPoints.append(maxPoint)
		if len(irisPoints) > 5:
			iris.append(cv2.fitEllipse(np.array(irisPoints)))
	return iris
예제 #9
0
def findEllipseContour(img, gradient_magnitude, gradient_orientation, estimatedCenter, estimatedRadius, nPts=30):
	center_point_coords = (int(estimatedCenter[0]), int(estimatedCenter[1]))
	P = getCircleSamples(center = estimatedCenter, radius = estimatedRadius, nPoints=nPts)
	for (x,y,dx,dy) in P:
		point_coords = (int(x),int(y))
		cv2.circle(img, point_coords, 2, bgr_yellow, 2)
		cv2.line(img, point_coords, center_point_coords, bgr_yellow)

	newPupil = np.zeros((nPts,1,2)).astype(np.float32)
	t = 0
	for (x,y,dx,dy) in P:
		#< define normalLength as some maximum distance away from initial circle >
		#< get the endpoints of the normal -> p1,p2>
		point_coords = (int(x),int(y))
		normal_gradient = dx, dy
		#cv2.circle(img, point_coords, 2, bgr_blue, 2)
		max_point = findMaxGradientValueOnNormal(gradient_magnitude, gradient_orientation, point_coords, center_point_coords, normal_gradient)
		cv2.circle(img, tuple(max_point), 2, bgr_red, 2) #locate the max points
		#< store maxPoint in newPupil>
		newPupil[t] = max_point
		t += 1
	#<fitPoints to model using least squares- cv2.fitellipse(newPupil)>
	return cv2.fitEllipse(newPupil)
예제 #10
0
def circleTest(nPts, C, circleRadius):
    P = getCircleSamples(center=C, radius=circleRadius, nPoints=nPts)
    return P
def circleTest(nPts,C,circleRadius):
    P = getCircleSamples(center=C, radius=circleRadius, nPoints=nPts)
    return P
예제 #12
0
    #2.2.2
    # grad_x: the first derivative that shows high changes, when looking at the image horizontally (it doesn't show that good tough, can multiply its value to show better...grad_x*100)
    # grad_y: the first derivative that shows high changes, when looking at the image vertically (also doesn't show that good, can multiply its value to show better...grad_y*100)
    # grad_d: has high values where there are high changes in intensity - around the pupil, the glints and eyelashes and barely around the iris
    # grad_m: shows the image as a relief map based on intensity changes

    return (grad_x, grad_y), grad_d, grad_m


def circleTest(gray, pupilBlob, pupilEllipse, (Gx, Gy), Gd, Gm):
    nPts = 20
    centroid = (int(pupilBlob['Centroid'][0]), int(pupilBlob['Centroid'][1]))
    (height, width) = pupilEllipse[1]
    circleRadius = int(height) / 2
    normalLength = 10
    P = getCircleSamples(center=centroid, radius=circleRadius, nPoints=nPts)
    samplePoints = []
    normals = []
    P2 = getCircleSamples(center=centroid,
                          radius=circleRadius + normalLength,
                          nPoints=nPts)
    for (x, y, dx, dy) in P:
        samplePoint = (int(x), int(y))
        samplePoints.append(samplePoint)
    for (x, y, dx, dy) in P2:
        normal = (int(x), int(y))
        normals.append(normal)
    for i in range(nPts):
        cv2.circle(Gm, samplePoints[i], 1, (255, 0, 255), 5)
        cv2.line(Gm, samplePoints[i], normals[i], (255, 0, 255))
    cv2.imshow("TempResults",
    #cv2.imshow("ThresholdPupil",grad_d)
    #2.2.2
    # grad_x: the first derivative that shows high changes, when looking at the image horizontally (it doesn't show that good tough, can multiply its value to show better...grad_x*100)
    # grad_y: the first derivative that shows high changes, when looking at the image vertically (also doesn't show that good, can multiply its value to show better...grad_y*100)
    # grad_d: has high values where there are high changes in intensity - around the pupil, the glints and eyelashes and barely around the iris
    # grad_m: shows the image as a relief map based on intensity changes

    return (grad_x, grad_y),grad_d, grad_m

def circleTest(gray,pupilBlob,pupilEllipse,(Gx,Gy),Gd,Gm):
    nPts = 20
    centroid = (int(pupilBlob['Centroid'][0]),int(pupilBlob['Centroid'][1]))
    (height,width)=pupilEllipse[1]
    circleRadius = int(height)/2
    normalLength=10
    P= getCircleSamples(center=centroid, radius=circleRadius, nPoints=nPts)
    samplePoints=[]
    normals=[]
    P2= getCircleSamples(center=centroid, radius=circleRadius+normalLength, nPoints=nPts)
    for (x,y,dx,dy) in P:
        samplePoint=(int(x),int(y))
        samplePoints.append(samplePoint)
    for (x,y,dx,dy) in P2:
        normal=(int(x),int(y))
        normals.append(normal)
    for i in range(nPts):
        cv2.circle(Gm,samplePoints[i], 1,(255,0,255),5)
        cv2.line(Gm,samplePoints[i],normals[i],(255,0,255))
    cv2.imshow("TempResults", Gm) #display the gradients magnitude with circle sample
    return None