简体   繁体   English

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

[英]How to compare the contents of two images using sikuli?

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")

It is always giving pop up hi not hello... though i haven't changed the screen.它总是弹出你好,而不是你好......虽然我没有改变屏幕。

I can understand that these two are two different images names that's why always the else block is working.我可以理解这两个是两个不同的图像名称,这就是 else 块始终有效的原因。 But is it possible to compare these two images.但是有可能比较这两个图像。 Contents of two images where there is some difference between the two.两个图像的内容,其中两者之间存在一些差异。 Was unable to upload the code so have commented it.. Help if anyone knows.无法上传代码,因此对其进行了评论。如果有人知道,请帮助。

http://doc.sikuli.org/finder.html <-- another way for looking inside of something http://doc.sikuli.org/finder.html <--另一种查看事物内部的方式

Ideally Sikuli works if you already have an image that your comparing against what's found on the screen.理想情况下,如果您已经有一个图像与屏幕上找到的图像进行比较,则 Sikuli 可以工作。 Below I dynamically create a region, then snap a picture, and finally compare the saved picture against what in the dynamically created region.下面我动态创建一个区域,然后截图,最后将保存的图片与动态创建的区域中的图片进行比较。

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....

This one is more like what you want i beleive.这个更像是你想要的,我相信。 You can take three different pictures and then a smaller picture of the one yout want.您可以拍摄三张不同的照片,然后拍摄一张您想要的小照片。 If you call getScore() it will return precent match http://doc.sikuli.org/match.html#Match如果您调用getScore()它将返回getScore() match http://doc.sikuli.org/match.html#Match

imagePath1 = capture('Match obj take large picture') # snapshots the screen
matchObj1 = exists(imagePath1) #Make match object

imagePath2 = capture('Match obj take large picture') # snapshots the screen
matchObj2 = exists(imagePath2) #Make match object

imagePath3 = capture('Match obj take large picture') # snapshots the screen
matchObj3 = exists(imagePath3) #Make match object

imagePath4 = capture('Target, take small picture') # snapshots the screen 
patternIwant = Pattern(imagePath4) #Make a pattern object search against

matchList = [matchObj1, matchObj2, matchObj3]

for m in matchList:
    arg = m.exists(patternIwant)
    if arg != None:
        print 'image score  ', arg.getScore()
    else:
        print 'no match'
    if m.exists(patternIwant):
        print "hello"
    else:
        print "hi"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM