2012-07-19 105 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"