How to avoid sikuli creating a png file when using "with Region" - sikuli

I have the following code in sikulix (version 2015-01-06)
...
t = wait("total_power.png")
area = Region(t.x+t.w, t.y, 80, 31)
with Region(area):
wait("num_1.png")
....
I find that "with Region" will create a png file in the same directory of the python file. And the png file is the region that I want.
How can I avoid it?

What is is it that you are trying to do here?
Is it that you would like to wait until a window appears, and then look inside that window for another picture to appear?
In that case you alreay have defined the region when you found "t".
"t" is the location of the picture "total_power.png"
For example:
# Wait until the window appears.
p1 = wait("image1.png")
# Find another picture inside the window.
p2 = p1.wait("image2.png")
Edit:
You should have a look here: Link
I think you could use the .right(), if you leave the () empty you take everything.
If fill in a a value you take a part of the screen.
I use .hightlight() when programming to show me what region I am looking at.
You can also use region1.union(region2) to merge 2 region to a new one.
An example:
Image1 = ("image1.png")
class Blue():
def __init__(self):
# Find an image.
LocImage1 = find(Image1)
# Too show the user the region we selected, we can highlight if for 5 seconds.
LocImage1.highlight(5)
# Grab the region to the right of this image.
LocImage1RightSide = LocImage1.right()
# Highlight the region again.
LocImage1RightSide.highlight(5)
# Run class
Blue()

Related

how to save the generated images from this code separated

I have run StarGAN Code from github, this code generate all the generated images in one picture.
How I can save all the generated images separated to single folder? I do not want to save all the images in one picture.
this is how it generate the output (sample image
I want to save the generated images from the trained model, not as samples with all the images in one picture but just a file that contains all the generated images.
This is the part of the code i want to change it
# Translate fixed images for debugging.
if (i+1) % self.sample_step == 0:
with torch.no_grad():
x_fake_list = [x_fixed]
for c_fixed in c_fixed_list:
x_fake_list.append(self.G(x_fixed, c_fixed))
x_concat = torch.cat(x_fake_list, dim=3)
sample_path = os.path.join(self.sample_dir, '{}-images.jpg'.format(i+1))
save_image(self.denorm(x_concat.data.cpu()), sample_path, nrow=1, padding=0)
print('Saved real and fake images into {}...'.format(sample_path))
The generator self.G is called on each element of c_fixed_list to generate images. All results are concatenated, then saved using torchvision.utils.save_image.
I don't see what's holding you from saving the images inside the loop. Something that would resemble:
for j, c_fixed in enumerate(c_fixed_list):
x_fake = self.G(x_fixed, c_fixed)
for k in range(len(x_fake)):
sample_path = os.path.join(self.sample_dir, f'{i+1}-{k}-feat{j}-image.jpg')
save_image(self.denorm(x_fake.data[k].cpu()), sample_path, nrow=1, padding=0)

Sublime Text 2/3 - How to always have at least 10 lines under current line?

Is there a way to show at least x number of lines below a current line in ST? Say my cursor is on line 55, I want Sublime to display at least 10 more lines below the current line so line 55 will never be at the bottom of the screen. Is this possible in Sublime?
You can achieve this with a simple plugin, that listens for cursor movement events.
From the Tools menu in Sublime Text, click New Plugin.
Replace the contents with the following:
import sublime, sublime_plugin
class ShowLinesUnderSelectionListener(sublime_plugin.EventListener):
def show_lines_under_selection(self, view, number_of_lines_to_show):
cursor_pos = view.sel()[0].end()
row, col = view.rowcol(cursor_pos)
desired_pos = view.text_point(row + number_of_lines_to_show, col)
if not view.visible_region().contains(desired_pos):
view.show(desired_pos, False)
def on_post_text_command(self, view, command_name, args):
if command_name in ('word_highlight_click', 'move', 'move_to', 'insert'):
self.show_lines_under_selection(view, 10)
def on_post_window_command(self, window, command_name, args): # for Vintageous support
if command_name in ('press_key'):
self.show_lines_under_selection(window.active_view(), 10)
Save it to the folder it suggests as something like show_lines_under_cursor.py.
This will ensure that there are always 10 visible lines under the cursor. Note that once you reach the bottom of the file, it won't scroll any further to show 10 non-existing-in-file lines. I'm not sure if this is possible via the API.

How to Find Exact match of an Image in Sikuli with Java

Am new to Sikuli and trying to Automate Citirx Application. Need Help
Am trying to select a user role in a screen, The screen has multiple roles and hence i need to scroll down the screen and search for a particular Role and click the Role.
I have Captured image of a Particular Role that i need to select and used below Code. In the second Image i have highlighted the Role i need to select in Red
Below is the Code an Trying:
Creating a Method:
public static boolean clipExist(Screen screen, String clip )
{
Match m = screen.exists(clip);
if(m != null)
{
return true;
}
else
{
return false;
}
}
Using the Method:
while(! clipExist(screen, "C:\\Users\\Satish_D1\\workspace\\Sikuli Demo\\Images\\DownArrow.PNG"))
{
screen.wheel(1 , 3);
if(clipExist(screen, "C:\\Users\\Satish_D1\\workspace\\Sikuli Demo\\Images\\Roles\\UK\\ENTP\\GEDIS_SALES_SUPPORT_ORL_CPF2.0_UK_ENTP.PNG"))
{
screen.doubleClick("C:\\Users\\Satish_D1\\workspace\\Sikuli Demo\\Images\\Roles\\UK\\ENTP\\GEDIS_SALES_SUPPORT_ORL_CPF2.0_UK_ENTP.PNG",0);
break;
}
}
The image recognision uses per default a similarity of 0.7 (see description of Patterns in SikuliX Documentation). That means SikuliX looks for 'pretty similar' images. You can specify the similarity for the pattern recognision thanks to the method similar, or in your case use the method exact.
In your method clipExist, you should replace the name of the image:
Match m = screen.exists(clip);
by:
Match m = screen.exists(Pattern(clip).exact())
It seems SikuliX 1.1 experience some problem with finding the text on a screen, but recognition works. You might want to scan the entire text screen by screen and split the lines. Next compare each line with the required role and save the degree of similarity. Select the line with the biggest similarity. In Python/Jython exists a special function for that in difflib module.
similarity = difflib.SequenceMatcher(None, string_a, string_b)
Here are the alternatives that you can do.
First alternative: capture scrollbar
Capture the down arrow in the scrollbar
Capture the image when you reach the end of scrollbar. The image contains the scroll progress and the down arrow of the scrollbar
Click down arrow until you find image of (2)
This method have drawback i.e. when the number of items are dynamic, the visual appearance of (2) will be different especially the scroll progress. However, this can be tricked by capturing only the lower part of scroll progress and the arrow. Please note that your mouse may make difficulty in (3) because you may not find (2) when it is covered by mouse. To handle this, every time you click down arrow, you may hover your mouse a bit before checking for (2). This is the complete script:
down_arrow = "downarrow.png"
complete_scroll = "completescroll.png"
while not exists(complete_scroll):
click(down_arrow)
hover(Location(300, 200))
Second alternative, use keyboard (down key)
Click anywhere in the items to be scrolled and do some type(Key.DOWN) for the number of item you have. In case you have dynamic number of item, you may do type(Key.DOWN) for any number that always bigger than your number of items. Here is the script to do
inside_item = "inside.png"
for n in range(10000):
type(Key.DOWN)
Hope it helps
I used 's' as a screen class reference. Hence, once we get an image then we will set the region for the same followed by the required image where you want to click
public static void main(String args[])
{
Match m = s.find("IMAGE");
Region r = new Region(m.x+11, m.y+22,12,12);
r.click();
s.find("ENTPIMAGE.PNG");
r.click("ENTPIMAGE.PNG");
}

Sikuli interact with more than 1 matching object

Hello so for example I have 4 balls that I must right click on, but when I right click them, nothing about the balls changes, how can I make it so that sikuli right clicks each of the balls and doesn't just get stuck on one of them?
You can use a for loop to search for all the balls.
Then in the for loop you can define what to do with it once found.
For example (Sikuli with Python):
Image_Balls = ()
for x in findAll(Image_Balls):
click(x)
Between the () you need to place a picture of how a ball looks like.
In this example he will find every ball on the screen and click on it.
You can also add a try, catch/exception in the for loop.
Then he will find every ball, and try to right click.
If the try failed, he will execute the catch (exception in python).
And will continue to look for the next ball, until there are no anymore.
Image_Balls = ()
for x in findAll(Image_Balls):
try:
rightClick(x)
except:
pass

Imwrite command didn't create an image with true value in Matlab

I'm trying to write .tif image. I wrote the following command either on command window or within function file in Matlab to write tif image with the name of 'A_exam'.
All value of output image (A_exam.tif) are 255, no image displayed, just white screen. A matrix is extracted from following code. When I calculated this code, values of A matrix are correct. The problem just comes from writing an image file.
[~,Ind_max] = max(vgt,[],3);
A= arrayfun(#(y) ...
arrayfun(#(x) emp(x,y, Ind_max(x,y)), 1:size(vgt,1)), ...
1:size(vgt,2), 'UniformOutput',false);
A = reshape([A{:}], size(Ind_max))
imwrite(A,'A_exam.tif','tif')
Thank you
whos A
Name Size Bytes Class Attributes
A 41x41 6724 single
That reshape before calling imwrite looks problematic. I would change the
imwrite(A,'A_exam.tif','tif')
to add a call to mat2gray
imwrite(mat2gray(A),'A_exam.tif');
to make sure you're not mixing matrices and images.