我正在尝试创建一个 OCR Android 应用程序。我已经有一个 python 脚本,我正在尝试用 chaquopy 来实现它。我在
build.gradle
中进行了必要的配置。
python{
version "3.8"
buildPython "C:/Users/user/AppData/Local/Programs/Python/Python38/python.exe"
pip {
// A requirement specifier, with or without a version number:
install "packaging"
install "pillow"
install "pytesseract"}
}
这是 src/main/Python/ocr.py 中的脚本
import pytesseract
from PIL import Image as PIL_image
pytesseract.pytesseract.tesseract_cmd =\
r'C:\Program Files\Tesseract-OCR\tesseract.exe'
tessdata_dir_config = r'--tessdata-dir "C:\Users\user\AndroidStudioProjects\teepee\app\src\main\python\tessdata"'
def bitmaptoString(bitmap):
res= pytesseract.image_to_string(bitmap, lang='eng', config=tessdata_dir_config)
return res
def test():
return "chaquopy in the works"
调用此方法时:
python = Python.getInstance();
PyObject pobj = python.getModule("ocr");
String ouText=pobj.callAttr("bitmaptoString",bitmap.toString()).toString();
Log.e("_______________","TESSER:");
Log.e("OUTPUT_OF_PYFUNC",ouText);
它说找不到tesseract:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://media/external/images/media/10101 flg=0x1 launchParam=MultiScreenLaunchParams { mDisplayId=0 mFlags=0 } (has extras) }} to activity {com.example.teepee/com.example.teepee.mainActivity}: com.chaquo.python.PyException: TesseractNotFoundError: C:\Program Files\Tesseract-OCR\tesseract.exe is not installed or it's not in your PATH. See README file for more information.
我还尝试使用 vcpkg 构建静态正方体并将路径添加到可执行文件,但发生了同样的问题。
我真的需要你的帮助。
我也遇到同样的问题,请问你找到解决办法了吗?