Question #649152 on Sikuli changed: https://answers.launchpad.net/sikuli/+question/649152
Status: Open => Answered RaiMan proposed the following answer: Since it is so easy, people tend to capture their images rather broadly than putting the cutting line very near around the main aspects (e.g. a button). "towards the edges" in this case means the the edges of the captured image, an example: - you have a button measuring 300 x 100 pixels (width x height) at the exact bounds of the button - you capture broadly around an get an image measuring 500 x 200 - this means you have a "surrounding background towards the edges" of top/bottom each 50 pixel and left/right each 100 pixel (supposing the capturing has the button centered) now the mentioned background-ration: - image if interest has 300x100 = 30.000 pixels - surrounding background is 2x300x50 + 2x200x100 = 30.000 + 40.000 = 70.000 pixels since the search algorithm is a statistical calculation over all pixels of the captured image (see the matchTemplate() feature of OpenCV) in this case, the weight of the background is about times 2.3 to the real button pixels. So if only a few pixels in the background of the current search region differ from the situation, where the image was captured, this will influence the match score, the more the surrounding background differs around the button borders. My experience is that the surrounding background should be less then 20% of the total image pixels. In this case this maximum would be about 7.000 pixels, meaning that you have to capture as near as about 4 pixels around the button edges, which you would normally only do, if you knew about the possible problems. if interested - these are the formulas: - size of image of interest: imgInterest - size of captured image: imgComplete - the challenge: imgInterest = 0.8 x imgComplete - the max background maxBack = (5 * imgInterest) / 4 - imgInterest - supposing even pixels around image of interest (edgePixels): (2 * imageInterestWidth + 2 * imageInterestHeight) * edgePixels + 4 * edgePixels * edgePixels = maxBack this can be solved according to the binomial: a * a + 2 * a * b + b * b = someValue ... and this is a script to calculate the edge pixels import math imgInterestW = 300 imgInterestH = 100 imgInterest = imgInterestW * imgInterestH maxBack = 5 * imgInterest / 4 - imgInterest edge = 0 # the edge pixels # the binomial formula aspects # a * a + 2 * a * b + b * b = someValue # (2 * imgInterestWidth + 2 * imgInterestHeight) * edge + 4 * edge * edge = maxBack # binom2b = (2 * imgInterestW + 2 * imgInterestH) binomb = imgInterestW + imgInterestH binombSq = binomb * binomb # binom2b * edge + 4 * edge * edge = maxBack # binombSq + binom2b * edge + 4 * edge * edge = maxBack + binombSq # (binomb + 2 * edge) * (binomb + 2 * edge) = maxBack + binombSq # (binomb + 2 * edge) = math.sqrt(maxBack + binombSq) edge = (math.sqrt(maxBack + binombSq) - binomb) / 2 print "for an image of interest having %d x %d (width x hight)" % (imgInterestW, imgInterestH) print "the capture should be maximum %d pixels around" % edge -- You received this question notification because your team Sikuli Drivers is an answer contact for Sikuli. _______________________________________________ Mailing list: https://launchpad.net/~sikuli-driver Post to : sikuli-driver@lists.launchpad.net Unsubscribe : https://launchpad.net/~sikuli-driver More help : https://help.launchpad.net/ListHelp