def main(): set_window_top() print u'本软件针对 http://cn.vonvon.net/quiz/743 颜色自动找色' print u'使用默认偏移量还是手动设置偏移量? y/n\n> ', choice = raw_input() offset_x, offset_x_r, offset_y, offset_y_r = 0, 0, 0, 0 if choice == 'y': offset_x = 770 offset_y = 265 offset_x_r = 1145 offset_y_r = 640 elif choice == 'n': print u'稍后设置偏移量, 提前将鼠标放置在方块最左上角' count_down(3) offset_x, offset_y = win32api.GetCursorPos() print u'设置偏移量, 将鼠标放在右下角' count_down(3) offset_x_r, offset_y_r = win32api.GetCursorPos() print u'自动寻找色块开始...' global im count = 50 while count: count -= 1 im = grab((offset_x, offset_y, offset_x_r, offset_y_r)) mouse_move([sum(i) for i in zip((offset_x, offset_y), get_position())]) sleep(0.1) mouse_click() sleep(0.2)
def snapshot(image=None, size=None): r"""Acquires an image as a numpy array. If the image argument is None, a screenshot is grabbed. otherwise, the given image is converted to a 2- or 3-dimensional numpy array, depending on whether it's colour or grayscale. """ if isinstance(image, ndarray): return image if image == None: try: from ImageGrab import grab image = grab() image.save("screenshot.png") except: from os import system name = "screenshot.png" command = "scrot %s" % name system(command) image = loadimage(name) elif isinstance(image, basestring): image = loadimage(image) image.load() if size != None: (m, n) = size image = image.resize((n, m), ANTIALIAS) return dstack(fromimage(channel) for channel in image.split())
def takeAShot(self): if grab: img = grab() img_path = os.path.join(SCREEN_DIR,datetime.datetime.now().strftime("%Y%m%d%H%M%S")+'.jpg') img.save(img_path) return img_path return ''
def isMyTurn(): img = grab() img = img.resize((800, 600),BICUBIC) img = img.crop((614, 248, 685, 292)) img = img.crop((7,19,59,33)) img = img.convert('LA') pix = img.load() w, h = img.size count = 0 for x in range(w): for y in range(h): #print pix1[x, y] if pix[x, y][0] == 0: count = count + 1 if count < 75 or count > 85: return False else: print 'MyTurn Confirmed' return True