← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #693078]: find the upper and left image in multiple images

 

Question #693078 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/693078

juan posted a new comment:
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)

-- 
You received this question notification because your team Sikuli Drivers
is an answer contact for Sikuli.