(self, thresholded, pupilrect=False)
return self.settings['pupilpos'], pupil.count(), self.settings['pupilbounds']
Get the pupil center, bounds, and size, based on the thresholded
		image; please note that the pupil bounds and size are very
		arbitrary: they provide information on the pupil within the
		thresholded image, meaning that they would appear larger if the
		camera is placed closer towards a subject, even though the
		subject's pupil does not dilate
		
		arguments
		thresholded		--	a pygame.surface.Surface instance, as
						returned by threshold_image
		
		keyword arguments
		pupilrect		--	a Boolean indicating whether pupil searching
						rect should be applied or not
						(default = False)
		
		returns
		pupilcenter, pupilsize, pupilbounds
					--	pupilcenter is an (x,y) position tuple that
						gives the pupil center with regards to the
						image (where the top left is (0,0))
						pupilsize is the amount of pixels that are
						considered to be part of the pupil in the
						thresholded image; when no pupilbounds can
						be found, this will return (-1,-1)
						pupilbounds is a (x,y,width,height) tuple,
						specifying the size of the largest square
						in which the pupil would fit
Get the pupil center, bounds, and size, based on the thresholded
		image; please note that the pupil bounds and size are very
		arbitrary: they provide information on the pupil within the
		thresholded image, meaning that they would appear larger if the
		camera is placed closer towards a subject, even though the
		subject's pupil does not dilate
		
		arguments
		thresholded		--	a pygame.surface.Surface instance, as
						returned by threshold_image
		
		keyword arguments
		pupilrect		--	a Boolean indicating whether pupil searching
						rect should be applied or not
						(default = False)
		
		returns
		pupilcenter, pupilsize, pupilbounds
					--	pupilcenter is an (x,y) position tuple that
						gives the pupil center with regards to the
						image (where the top left is (0,0))
						pupilsize is the amount of pixels that are
						considered to be part of the pupil in the
						thresholded image; when no pupilbounds can
						be found, this will return (-1,-1)
						pupilbounds is a (x,y,width,height) tuple,
						specifying the size of the largest square
						in which the pupil would fit
Get the pupil center bounds and size based on the thresholded image ; please note that the pupil bounds and size are very arbitrary : they provide information on the pupil within the thresholded image meaning that they would appear larger if the camera is placed closer towards a subject even though the subject s pupil does not dilate arguments thresholded -- a pygame . surface . Surface instance as returned by threshold_image keyword arguments pupilrect -- a Boolean indicating whether pupil searching rect should be applied or not ( default = False ) returns pupilcenter pupilsize pupilbounds -- pupilcenter is an ( x y ) position tuple that gives the pupil center with regards to the image ( where the top left is ( 0 0 )) pupilsize is the amount of pixels that are considered to be part of the pupil in the thresholded image ; when no pupilbounds can be found this will return ( - 1 - 1 ) pupilbounds is a ( x y width height ) tuple specifying the size of the largest square in which the pupil would fit
def find_pupil(self, thresholded, pupilrect=False):
		
		"""Get the pupil center, bounds, and size, based on the thresholded
		image; please note that the pupil bounds and size are very
		arbitrary: they provide information on the pupil within the
		thresholded image, meaning that they would appear larger if the
		camera is placed closer towards a subject, even though the
		subject's pupil does not dilate
		
		arguments
		thresholded		--	a pygame.surface.Surface instance, as
						returned by threshold_image
		
		keyword arguments
		pupilrect		--	a Boolean indicating whether pupil searching
						rect should be applied or not
						(default = False)
		
		returns
		pupilcenter, pupilsize, pupilbounds
					--	pupilcenter is an (x,y) position tuple that
						gives the pupil center with regards to the
						image (where the top left is (0,0))
						pupilsize is the amount of pixels that are
						considered to be part of the pupil in the
						thresholded image; when no pupilbounds can
						be found, this will return (-1,-1)
						pupilbounds is a (x,y,width,height) tuple,
						specifying the size of the largest square
						in which the pupil would fit
		"""
		
		
		# cut out pupilrect (but only if pupil bounding rect option is on)
		if pupilrect:
			# pupil rect boundaries
			rectbounds = pygame.Rect(self.settings['pupilrect'])
			# correct rect edges that go beyond image boundaries
			if self.settings['pupilrect'].left < 0:
				rectbounds.left = 0
			if self.settings['pupilrect'].right > self.camres[0]:
				rectbounds.right = self.camres[0]
			if self.settings['pupilrect'].top < 0:
				rectbounds.top = 0
			if self.settings['pupilrect'].bottom > self.camres[1]:
				rectbounds.bottom = self.camres[1]
			# cut rect out of image
			thresholded = thresholded.subsurface(rectbounds)
			ox, oy = thresholded.get_offset()
		
		# find potential pupil areas based on threshold
		th = (self.settings['threshold'],self.settings['threshold'],self.settings['threshold'])
		mask = pygame.mask.from_threshold(thresholded, self.settings['pupilcol'], th)
		
		# get largest connected area within mask (which should be the pupil)
		pupil = mask.connected_component()
		
		# get pupil center
		pupilcenter = pupil.centroid()
		
		# if we can only look within a rect around the pupil, do so
		if pupilrect:
			# compensate for subsurface offset
			pupilcenter = pupilcenter[0]+ox, pupilcenter[1]+oy
			# check if the pupil position is within the rect
			if (self.settings['pupilrect'].left < pupilcenter[0] < self.settings['pupilrect'].right) and (self.settings['pupilrect'].top < pupilcenter[1] < self.settings['pupilrect'].bottom):
				# set new pupil and rect position
				self.settings['pupilpos'] = pupilcenter
				x = pupilcenter[0] - self.settings['pupilrect'][2]/2
				y = pupilcenter[1] - self.settings['pupilrect'][3]/2
				self.settings['pupilrect'] = pygame.Rect(x,y,self.settings['pupilrect'][2],self.settings['pupilrect'][3])
			# if the pupil is outside of the rect, return missing
			else:
				self.settings['pupilpos'] = (-1,-1)
		else:
			self.settings['pupilpos'] = pupilcenter
		
		# get pupil bounds (sometimes failes, hence try-except)
		try:
			self.settings['pupilbounds'] = pupil.get_bounding_rects()[0]
			# if we're using a pupil rect, compensate offset
			if pupilrect:
				self.settings['pupilbounds'].left += ox
				self.settings['pupilbounds'].top += oy
		except:
			# if it fails, we simply use the old rect
			pass
		
		return self.settings['pupilpos'], pupil.count(), self.settings['pupilbounds']
def find_pupil ( self , thresholded , pupilrect = False ) : # cut out pupilrect (but only if pupil bounding rect option is on) if pupilrect : # pupil rect boundaries rectbounds = pygame . Rect ( self . settings [ 'pupilrect' ] ) # correct rect edges that go beyond image boundaries if self . settings [ 'pupilrect' ] . left < 0 : rectbounds . left = 0 if self . settings [ 'pupilrect' ] . right > self . camres [ 0 ] : rectbounds . right = self . camres [ 0 ] if self . settings [ 'pupilrect' ] . top < 0 : rectbounds . top = 0 if self . settings [ 'pupilrect' ] . bottom > self . camres [ 1 ] : rectbounds . bottom = self . camres [ 1 ] # cut rect out of image thresholded = thresholded . subsurface ( rectbounds ) ox , oy = thresholded . get_offset ( ) # find potential pupil areas based on threshold th = ( self . settings [ 'threshold' ] , self . settings [ 'threshold' ] , self . settings [ 'threshold' ] ) mask = pygame . mask . from_threshold ( thresholded , self . settings [ 'pupilcol' ] , th ) # get largest connected area within mask (which should be the pupil) pupil = mask . connected_component ( ) # get pupil center pupilcenter = pupil . centroid ( ) # if we can only look within a rect around the pupil, do so if pupilrect : # compensate for subsurface offset pupilcenter = pupilcenter [ 0 ] + ox , pupilcenter [ 1 ] + oy # check if the pupil position is within the rect if ( self . settings [ 'pupilrect' ] . left < pupilcenter [ 0 ] < self . settings [ 'pupilrect' ] . right ) and ( self . settings [ 'pupilrect' ] . top < pupilcenter [ 1 ] < self . settings [ 'pupilrect' ] . bottom ) : # set new pupil and rect position self . settings [ 'pupilpos' ] = pupilcenter x = pupilcenter [ 0 ] - self . settings [ 'pupilrect' ] [ 2 ] / 2 y = pupilcenter [ 1 ] - self . settings [ 'pupilrect' ] [ 3 ] / 2 self . settings [ 'pupilrect' ] = pygame . Rect ( x , y , self . settings [ 'pupilrect' ] [ 2 ] , self . settings [ 'pupilrect' ] [ 3 ] ) # if the pupil is outside of the rect, return missing else : self . settings [ 'pupilpos' ] = ( - 1 , - 1 ) else : self . settings [ 'pupilpos' ] = pupilcenter # get pupil bounds (sometimes failes, hence try-except) try : self . settings [ 'pupilbounds' ] = pupil . get_bounding_rects ( ) [ 0 ] # if we're using a pupil rect, compensate offset if pupilrect : self . settings [ 'pupilbounds' ] . left += ox self . settings [ 'pupilbounds' ] . top += oy except : # if it fails, we simply use the old rect pass return self . settings [ 'pupilpos' ] , pupil . count ( ) , self . settings [ 'pupilbounds' ]