我正在从我的android设备(OnePlus 5)上通过adb截取一些屏幕截图,以便通过Google tesseract识别页面中是否存在指定的单词。
通常需要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'
答案 0 :(得分:0)
对我来说,解决该错误的方法是删除以下路径中的pgrinder目录:/sdcard/pgrinder/screen.png。
我认为,如果目录不存在,它将生成目录,但事实并非如此。我不知道为什么它有时会起作用,有时却不起作用。但是自从我更改它以来,它每次都起作用。