find the upper and left image in multiple images

Asked by juan

I have the example script:
####
https://i.imgur.com/O6OwQ3l.png
####
I have to find all the images in the list, and if the number of images found is greater than a quantity, click on the image that matches those of the list, and it is in the row above, and further to the left .
####
https://i.imgur.com/RA9o358.png
####
I have managed to count the images, but I can't think of how to identify which one is the top left.

Thank you very much in advance for any ideas on how to do it.

####
Settings.image = {}
Settings.image[1] = "1600962830107.png"
Settings.image[2] = "1600962841115.png"
Settings.image[3] = "1600962862135.png"
Settings.image[4] = "1600962873853.png"

def cantidadImagen(imagen):
    cantidad = 0
    if exists(imagen):
        for i in findAll(imagen):
            cantidad = cantidad + 1
    return cantidad

def clickUpperLeftImage():
   #i don't know how

for i in range(1,5,1):
    total = cantidadImagen(Settings.image[i])
popup(str(total))
if total > 5:
   clickUpperLeftImage()

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
juan (fogelmanjg) said :
#1

I have solved it with some lists and matrices.
I do not know if it has been verbose, but it works.

#####
Settings.myRegion = Region(1, 1, 400, 400)
Settings.image[0] = "image1.png"
Settings.image[1] = "image2.png"
Settings.image[2] = "image3.png"
Settings.image[3] = "image4.png"
#I have a region to search,
#and an array of images to search within the region

def listImages(image,region):
#This function not only returns the number of images that match in the region,
#but it also returns a list with the coordinates of all the images.
    count = 0
    listX = [] #the X coordinates
    listY = [] #the Y coordinates
    if region.exists(image,0):
        for i in region.findAll(image):
            count += 1
            listX.append(i.getX())
            listY.append(i.getY())
    list = [count, listX, listY]
    return list

def clickUpperLeftImage(matrix,tolerance=25):
#all the images in a row are not exactly on the same line,
#so I gave it a tolerance
    upper = min(matrix[2])
    listY = []
    listX = []
    count = 0
    for i in range(0,matrix[0],1):
        if (matrix[2][i] - tolerance) < upper:
            count += 1
            listY.append(matrix[2][i])
            listX.append(matrix[1][i])
    matrix = [count,listX,listY]
    # matrix have only the coordinates of the images in the top row
    listY = []
    listX = []
    lefttier = min(matrix[1])
    for i in range(0,matrix[0],1):
        if matrix[1][i] == lefttier:
            y = matrix[2][i]
            x = matrix[1][i]
            break
    click(Location(x,y))

imageTotal = 0
matrixTotal[0,"",""]
#I have to look for all the occurrences, for each of the images to find
for i in range(0,len(Settings.image),1):
    matrixImage = listImages(Settings.image[i],settings.myRegion)
    imageTotal += matrixImage[0]
    #now I add the coordinates of each image found in a list where they will all be.
    for j in range(0,matrixImage[0],1):
        matrixTotal[1].append(matrixImage[1][j])
        matrixTotal[2].append(matrixImage[2][j])
if imageTotal > 9:
    clickUpperLeftImage(matrixTotal)

Revision history for this message
Launchpad Janitor (janitor) said :
#2

This question was expired because it remained in the 'Open' state without activity for the last 15 days.