我从我的安卓设备(OnePlus 5)通过亚行拍摄了一些屏幕截图,以便用谷歌识别页面内是否有特定的单词。
通常需要5-8个截图,每个截图之间有1.5秒的延迟。前2-4个屏幕截图可以打开,但随后会抛出错误,不能使用PIL、Paint.net或手机本身打开。
from adb.client import Client as AdbClient
from PIL import Image
import pytesseract
import os
# The Method with the Problem
# adb package is pure-python-adb
# after 2-4 calls of the method the error ocures
def get_screen(device):
device.shell("screencap -p /sdcard/pgrinder/screen.png")
device.pull("/sdcard/pgrinder/screen.png", "screen.png")
screens = ""
try:
**screens = Image.open('screen.png')**
except Exception:
print("error with image opening")
return -1
return screens
当前错误是: OSError:无法识别图像文件'C:\Users\kelle\PycharmProjects\PGrinder\tmp\screen.png‘
发布于 2019-05-19 23:24:13
修复这个bug的方法是删除路径/sdcard/ pgrinder /screen.png中的pgrinder目录。
我以为它会生成目录,如果它不存在,但事实并非如此。我不知道为什么它时而有效,时而无效。但自从我改变了它,它每次都起作用。
https://stackoverflow.com/questions/56203655
复制相似问题