← Back to team overview

sikuli-driver team mailing list archive

[Question #148363]: unfocus code snipet

 

New question #148363 on Sikuli:
https://answers.launchpad.net/sikuli/+question/148363

Basically a wrapper for an auto de-focus method. I wanted to pass in an image and have a method automatically adjust it's percent of recognition. figured i would share it and see what comments and suggestions i would get. One i have though of right now just stitting here i would like to pass the gui's own region method as is with out having to key in the actual numbers.


class unFocus():
	def target(self, image, percentmatch=0.70, regionlist=[0,0,0,0], offsetclick=[0,0]):
		"""This method aquires an object. It gives four chances to find and image starting with 70 percent match and degrading by 10 percent each loop. 
		The regionlist variable is optional, if you don't supply cordinates it will default with the screen cordinates. The off center click is optional too"""
		if regionlist==[0,0,0,0]:
			regionlist=[getBounds()]
		cannotfind = 0
		while True: 
			if Region(*regionlist).exists(Pattern(image).similar(percentmatch).targetOffset(*offsetclick)):
				return Region(*regionlist).exists(Pattern(image).similar(percentmatch).targetOffset(*offsetclick))
			else:
				if cannotfind ==4:
					return False
					#return popup("Error:\nImage "+image+" not found!")	
				percentmatch = percentmatch-10
				cannotfind = cannotfind+1

-- 
You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.