You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I didn't want to do a pull request because I only have an informal piece of code.
Here is a method to compare images returned by adbclient.takeSnapshot(). It provides nearly the same functionality as MonkeyImage.sameAs(). Instead of calling image1.sameAs(image2, 0.95), you call sameAs(image1, image2, 0.95). This new sameAs() function could easily be made a method of AdbClient.
# Requires Image from PIL
# Which should have been imported by the call to takeSnapshot()
def percentSame(image1, image2):
# If the images differ in size, return 0% same.
size_x1, size_y1 = image1.size
size_x2, size_y2 = image2.size
if (size_x1 != size_x2 or
size_y1 != size_y2):
return 0
# Images are the same size
# Return the percent of pixels that are equal.
numPixelsSame = 0
numPixelsTotal = sizze_x1 * size_y1
image1Pixels = image1.load()
image2Pixels = image2.load()
# Loop over all pixels, comparing pixel in image1 to image2
for x in range(size_x1):
for y in range(size_y1):
if (image1Pixels[x, y] == image2Pixels[x, y]):
numPixelsSame += 1
return float(numPixelsSame) / float(numPixelsTotal)
def sameAs(image1, image2, percent=1.0):
percentSame = percentSame(image1, image2)
return (percentSame >= percent)
The text was updated successfully, but these errors were encountered:
I didn't want to do a pull request because I only have an informal piece of code.
Here is a method to compare images returned by
adbclient.takeSnapshot()
. It provides nearly the same functionality asMonkeyImage.sameAs()
. Instead of callingimage1.sameAs(image2, 0.95)
, you callsameAs(image1, image2, 0.95)
. This newsameAs()
function could easily be made a method of AdbClient.The text was updated successfully, but these errors were encountered: