2013-12-14 47 views
1

是否有任何代碼可以檢測到任何像素顏色是否更改?Python:如何檢測屏幕上的任何更改

什麼我想要做的是檢測區域的任何變化,如果像素

所以如果像素的該區域的顏色改變,它提醒我。

對不起我的英文不好。

+0

什麼GUI工具包是您使用? – Thayne

+0

你到目前爲止嘗試過什麼?你的代碼是什麼?你正在使用哪個Python版本? – chill0r

回答

2

要查找連續截圖之間準確的區別:

#!/usr/bin/env python 
from PIL import ImageChops # $ pip install pillow 
from pyscreenshot import grab # $ pip install pyscreenshot 

im = grab() 
while True: # http://effbot.org/zone/pil-comparing-images.htm 
    diff = ImageChops.difference(grab(), im) 
    bbox = diff.getbbox() 
    if bbox is not None: # exact comparison 
     break 

print("bounding box of non-zero difference: %s" % (bbox,)) 
# superimpose the inverted image and the difference 
ImageChops.screen(ImageChops.invert(im.crop(bbox)), diff.crop(bbox)).show() 
input("Press Enter to exit") 
0

一個直觀的解決方案可能是folllowing:

1) Take the bytes of the region you want to check for changes 
2) Convert them to a string of bytes 
3) Use an hash function from the hashlib module 
4) Compare the obtained hash with the previous one 
    (if they're different something has changed) 

這種方法檢測到任何變化也是在光照條件下,因此可能不是你想要的。但是這確實檢測到圖像部分中的ANY變化

還有一些庫綁定,如PyOpenCV,可以做到這一點,還有更多。