如何使用sikuli比较两个图像的内容?

问题描述 投票:1回答:1
import shutil
import os
wait(5)
dir = os.path.dirname(getBundlePath()) # the folder, where your script is stored
img = capture(SCREEN) # snapshots the screen
shutil.move(img, os.path.join(dir, "shot.png")) # to make it persistent
wait(10)
dir = os.path.dirname(getBundlePath()) # the folder, where your script is stored
img2 = capture(SCREEN) # snapshots the screen
shutil.move(img2, os.path.join(dir, "shot2.png")) # to make it persistent
if img == img2:
    popup("hello")
else:
    popup("hi")

虽然我没有改变屏幕,但它始终是弹出嗨而不是你好...

我可以理解这两个是两个不同的图像名称,这就是为什么总是使用else块。但是可以比较这两个图像。两个图像的内容,两者之间有一些差异。无法上传代码所以评论了它..如果有人知道帮助。

python sikuli
1个回答
0
投票

http://doc.sikuli.org/finder.html

理想情况下,如果您已经有一个与屏幕上的内容进行比较的图像,Sikuli会工作。下面我动态创建一个区域,然后拍摄一张图片,最后将保存的图片与动态创建的区域中的图片进行比较。

imagePath1 = capture()  #snapshots the screen
image1 = exists(imagePath1)  #Create a Match object
imagePath2 = capture()  #snapshots the screen
image2 = Pattern(imagePath2)  #Create a Matach Object
myRegion = Region(image1)  #make new region from the match object
if myRegion.exists(image2): #look in the region
    print "hello" #yeah it's in the region of the screen
else:
    print "hi"  #nope not there....

这个更像你想要的我相信。您可以拍摄三张不同的照片,然后拍摄您想要的照片。如果你打电话给qazxsw poi,它将返回百分比匹配qazxsw poi

getScore()
© www.soinside.com 2019 - 2024. All rights reserved.