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

画面を変更していませんが、常にこんにちはではなくポップアップを表示しています...。

これら2つは2つの異なる画像名であることを理解できます。そのため、常にelseブロックが機能しています。しかし、これら2つの画像を比較することは可能ですか。2 つの画像の間に若干の違いがある 2 つの画像の内容。コードをアップロードできなかったので、コメントしました..誰かが知っていれば助けてください。

4

1 に答える 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....

これはあなたが望むものにもっと似ています。3 枚の異なる写真を撮ってから、必要な 1 枚の小さい写真を撮ることができます。呼び出すgetScore()と、最近の一致が返されます 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"
于 2012-07-20T15:23:58.600 に答える