Change Sikuli's sensitivity? - python

I've been using sikuli for awhile, however I have an issue with it... It's not sensitive enough. I'm trying to match something on the screen that is -EXACT-, and there are a few other items on the screen that look similar enough that sikuli is mistaking them for what I'm actually looking for, so I need to make it look for ONLY this item with no variances at all.
How can I do this?
Oh and to explain my issue a bit further, I am writing a loop for a game, once a progress bar has reached 100% - it needs to allow the loop to finish (And start over again), however the progress bar is just a plain bar - so when sikuli looks for it on the screen, it finds the partially complete bar (Since apparently it matches different lengths/widths/sizes of the image it is looking for), and triggers.

You can do the following in the Sikuli IDE:
Click on the image
In Pattern Settings > Matching Preview, drag the Similarity bar to 1.0 (all the way to the right)
Click OK

If you are using Sikuli IDE click image miniature, for which you want to change sensitivity. You will be presented screenshot of your desktop with and occurrences of pattern(your image). Below there is a slider witch changes sensitivity. While changing it you will notice that highlighted occurrences of the pattern increase or decrease accordingly.
This method assumes that you have your game on screen (so windowed mode, not fullscreen), but even if you don't you still can adjust sensitivity, just you won't see 'live' results of search.
If you call sikuli from Java code, you have to use Pattern(image.png).similar(y.xx)
where the argument of simmilar is something between 0.00 and 1.00.
I haven't used second method so you may need to experiment with it.

Will the following work?
You are looking for the progress to reach 100% then loop again?
f = open("C:\\test.htm",'W')
f.write('<font color="#347C2C">lOOPtEST</font><br />')
f.write('loop iteration' + (str (count)) + '<br />')
count = count + 1
f.close()
COUNT =10
POPUP("LOOPTEST")
//image compare from progress bar
import sikuli.Sikuli *
WebPath =('Z:\\ZZZautomation\\Web\\')
BuildPath = ("Z:\BUILDS\Daily_BUILDS\QA_MainBranch_Install\*.install")
BuildNumber = glob.glob("Z:\BUILDS\Daily_BUILDS\QA_MainBranch_Install\*.install")
for filename in BuildNumber:
SmokeTestInfo = "SmokeTest_Build " + filename[45:50] + " Iteration 44"+".htm"
global Number
Number = filename[45:50]
global SmokeTest
SmokeTest = SmokeTestInfo
global count
count = 0
defMidProgress():
while not exists ("//path to image of progress bar # 50%//",FOREVER)
//or
wait("//path to image of progress bar # 50%//", FOREVER)
//using forevEr means sikuli will checK FOR 50% PROGRESS FOREVER
//the bottom execures once the condition above is met
open(WebPath + SmokeTest,'w')
f.write('<font color="#0000FF">Progress is at 50%</font><br />')
f.close()
// writes entry to html log fie
defFinalProgress():
while not exists ("//path to image of progress bar # 100%//",FOREVER)
//or
wait("//path to image of progress bar # 100%//", FOREVER)
//using forever means sikuli will check FOR 100% PROGRESS FOREVER
//the bottom execures once the condition above is met
open(WebPath + SmokeTest,'a')
f.write('<font color="#0000FF">Progress is at 100%</font><br />')
f.close()
// writes entry to html log fie
def Loop
count =0
def midProgress():
def FinalProgress():

To match an exact image I use:
image1 = ("image1.png")
while not exists (Pattern(image1).exact()):
# Wait until that exact image appears.
wait(1)

Related

How to make a string blink for a specified time using the colored function in the termcolor module? [Python 2.7]

I am trying to figure out how I can use the blink attribute of the colored() function in the termcolor module to blink for a specific amount of time, and then stop.
I looked at the package index and the properties of this, but I haven't seen anywhere describing if this would be possible.
I currently have the following bit of code that makes the string blink indefinitely:
print(colored('Picking the first dealer by random...', 'cyan', attrs=['blink']))
I would like to be able to make this string blink for a couple of seconds, stop, and then continue running the program. Is there a possible way to do this?
This blink_once() function will show the word TEXT for .5 secs and will hide it for .5 secs afterwards.
So the effect is just a one time blink. I do it writing spaces in he same place as the text after a delay. It's easy to modify the delay or the text, or adding them as parameters if you need it for your specific project.
The blink(number) calls blink_once() a determined number of times. So blink(3) will show the word "TEXT" blinking 3 times.
import sys
import time
def blink_once():
sys.stdout.write('\rTEXT')
time.sleep(0.5)
b = ("Loading")
sys.stdout.write('\r ')
time.sleep(0.5)
def blink(number):
for x in range(0,number):
blink_once()
blink(3)

Change value of bokeh slider

I'd like to be able to change things about the slider (the value, the start/end values) programmatically.
So I take the standard slider.py demo, and just add this at the end:
for i in range(5):
amp_slider.value = amp_slider.value + 1
time.sleep(1)
That should move the value upwards every second for a few seconds. But the slider doesn't move. What am I doing wrong? Or similarly if I try to change the .end or .start value.
[I know sliders are supposed to be INPUT not OUTPUT devices. But nonetheless I'm trying to control its behavior.]
bokeh show() outputs the chart as html & javascript. Once it has done this it can no longer be modified (unless you wrote some javascript which was included to modify the page).
You need a library that renders in a 'dynamic' window (such as matplotlib to be able to replot a chart like this.
The only code inside your program that will be used again once the page is created is in the callback functions. If you adjust sliders.py so it reads:
def update_title(attrname, old, new):
amplitude.value += 1
Every time you update the text, the amplitude will increase.

python auto clears everything on screen after 298 lines

my problem is that python.exe auto clears everything ive printed to it, after a certain amount of lines has been reached, for example i created the following program
a = 0
for a in range(0, 10000):
print(str(a) + ':> cola')
delay = input('BLARG :>')
now when i ran this in python .exe, i got the following result.
IMAGE1, and it carried on like this till it reached the end. IMAGE2 now the problem is python erased everything in the first image that came before the 9701st print which is a tad troublesome, does anyone have any advice on how to prevent python auto clearing everything.
This is not a python problem. change settings of your console ~v1k45
Windows' CMD you're using have a limit of old output it remembers.
I don't have Windows in English, so I do translation of names of the options myself, and they can differ from reality.
To change the limit, right-click on it's title bar and select Properties (for current window, or Defaults to change it for all future cmd windows), go to the tab Layout and increase heigth of Buffer size:

Psychopy builder expt. - how to add live updating text on screen

I am creating an experiment using Psychopy builder.
The participant is presented with an image containing numbers, e.g. 10 and 20.
They enter what they think is the mean of the numbers, 15 in this case, and then press the spacebar to move on to the next image.
I am trying to have it so there is a display/box on screen that shows them their entry, as with larger numbers in the hundreds of thousands and millions I think they might lose track of what they have pressed.
The ability to change their entry would be excellent also, but really I am most interested in them being able to see it on screen.
In builder I can't find a way to do this, and the ratings scale is not appropriate for huge numbers.
I found these solutions in code to do something that sounds like it:
http://www.psychopy.org/wiki/home.php/Snippets/LiveUpdatingText
However when I try to add them using the code insert function , or just adding them to the compiled script the screen locks up when I try to run the experiment. I am a novice at python, and am not sure where to start fixing this. Is what I'm trying to do possible?
I'm happy to provide some example code from the compiled builder experiment.
Thanks in advance!
Those code snippets are designed for Coder, where you control everything that is happening and when. The same thing can be done in Builder, but you will have to amend the code to fit in with Builder's event loop cycle. i.e. Builder does certain things at the start of an experiment, on every trial, on every screen refresh and so on. So you can't just insert this sort of code without modification, because, for example, it attempts to wait indefinitely for a keypress. Builder meanwhile, is checking the keyboard every screen refresh (typically at 60 Hz), so if you try to wait indefinitely for a keypress in code, you'll be halting Builder from doing everything else it needs to do.
In essence, you just need to break up the code into snippets that go in the appropriate tab in a Builder Code Component (for code to be executed at experiment start, on each frame, and so on), and avoid indefinite functions like event.waitKeys() in favour of instantaneous checking via event.getKeys()
e.g. to adapt the second example from Jonas Lindeløv, in the "Begin Routine" tab, put:
chars = list('0123456789.') # the valid characters
meanText = '' # start with an empty answer on each trial
In the "Each Frame" tab, put something like:
response = event.getKeys() # get a list of keys pressed at this instant
if len(response) > 0: # if there was one,
key = response[0] # just convenient shorthand
if key in chars:
meanText = meanText + response[0]
elif key == 'space':
meanText = meanText + ' '
elif key == 'backspace' and len(meanText) > 0:
meanText = meanText[:-1]
elif key == 'return':
thisExp.addData('Answer', meanText) # save the response
continueRoutine = False # finish this trial
# update the appropriate text stimulus with the current response value:
insertNameOfYourTextStimulusComponent.text = meanText

Pygame text not updating

The following code is being looped - is in a loop - but when 'inputStr' changes, the display does not. Printing inputStr yields the expected results, though.
defFnt = pygame.font.Font("CP437.ttf", 72)
txtToRndr = defFnt.render(inputStr,False, (0,0,0))
disp.blit(txtToRndr, (100,300))
Download link; http://www.mediafire.com/download/a4hp9wgojxgiao9/functGroup.rar
If you print inputStr right before its rendered it prints for a bit then stops, meaning it isnt getting rendered after a certain point, Which i think is because this condition:
if (16-len(Gnots))>0:
it must be coming out false therefore the code to render the new text isnt being executed:
if you print Gnots after the condition, it prints it until its length is 16 items than stops
change the number 16 in the condition to say 1000 as a test than try typing and the text changes
Your code needs refactoring. As the other answer says, the main problem is that if-block (try changing it to if True:.
I would recommend capping the framerate but drawing every frame unconditionally, as this is simpler and more robust. You're also not clearing the screen each frame, and PyGame has nice key tokens (e.g. pygame.K_ESCAPE) which you should use instead of numbers. You're also loading the font each time you draw; you only need to do so once, at the top of your program.
Here's my PyGame basecode, which shows some of these best practices. In the draw() function, you'd add your fill call to clear the screen, and then all of your rendering code.
I can suggest the following after encountering similar issue.
Try updating the screen with your text by adding following line after your code:
pygame.display.update()
The issue of text not updating on screen was coming in my case as I was trying to take input from terminal and then updating in on pygame screen.

Categories

Resources