我正在学习尸检,所以我希望我能在这里找到帮助。我试图在我的屏幕上找到一个图像并将光标移动到它。
我写了以下代码:
import autopy
# Take a screenshot of the entire desktop
autopy.bitmap.capture_screen().save('screen.png')
# define a function to search for the image in the screenshot
def find_image_example():
aid = autopy.bitmap.Bitmap.open('aid.png') # searched image
screen = autopy.bitmap.Bitmap.open('screen.png') # Desktop screenshot
pos = screen.find_every_bitmap(aid,0.1) # find the image if any
if pos:
print('Found aid at: %s' % str(pos)) # print all found instances
x = pos[0][0] # x pos
y = pos[0][1] # y pos
print(x) # print for debug
print(y) # print for debug
autopy.mouse.smooth_move(x,y) # move the cursor to the first image
else:
print('no images found!') # print if no images found
# execute the function
find_image_example()
运行代码后,我收到以下错误消息:
Found aid at: [(405.0, 1000.0), (552.0, 1000.0), (699.0, 1000.0)]
405.0
1000.0
File "C:/Users/Mortada/PycharmProjects/autopy_tut/main.py", line 22, in <module>
find_image_example()
File "C:/Users/Mortada/PycharmProjects/autopy_tut/main.py", line 18, in find_image_example
autopy.mouse.smooth_move(x,y) # move the cursor to the first image
ValueError: Point out of bounds
我不确定这里出了什么问题:-/我以为我做对了,哈哈!