2012-07-19 38 views
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") 

它总是给弹出嗨不是你好......虽然我没有改变屏幕。如何比较使用sikuli的两个图像的内容?

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

+0

你似乎是比较包含文件名的字符串,而不是图像内容本身。尝试添加一些像'print(img)'和'print(img2)'这样的语句来理解正在发生的事情,并阅读有关如何实际比较图像的文档。 – gerrit 2012-07-19 08:08:47

+0

是的尝试过,它也给出了IMG的信息,但我想要在内容上有所不同 – user1537127 2012-07-19 09:42:03

回答

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

这一个更像是你想要我相信。你可以拍摄三张不同的照片,然后拍下你想要的照片。如果你打电话getScore()它将返回precent比赛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"